This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Another Objective-C compiler question
- From: Paul Johnson <pauljohn at ku dot edu>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 05 Sep 2002 09:07:19 -0500
- Subject: Another Objective-C compiler question
- Reply-to: pauljohn at ku dot edu
Yesterday I got an incredibly speedy answer from Nicola Pero about the
Objective-C compiler and a possible bug that I might have found. I have
submitted that one to gcc's GNATS.
So I am emboldened to ask about another problem that did not affect gcc
3.0.4 but does arise in 3.1 and 3.2.
This arises when we try to compile the Swarm libraries
(http://www.swarm.org).
Here is the compiler warning we see:
../../../swarm-2.1.140.20020514/src/analysis/Averager.m: In function
`-[Averager update]':
../../../swarm-2.1.140.20020514/src/analysis/Averager.m:153: warning:
comparison of distinct pointer types lacks a cast
make[1]: *** [Averager.lo] Error 1
The compiler's warning focuses on the comparison
GETLOC (iter) == (id) Member
that is embedded in this for loop:
for (obj = NEXT (iter); GETLOC (iter) == (id) Member; obj = NEXT
(iter))
I'm not a programmer by training and I hesitate to reveal my limitations
by trying to explain too much about how we end up using this approach.
Nevertheless, I will try. The entire Swarm source is available, but
building it requires the install of a few subsidiary libraries and I
doubt most people want to go to that length. In case you just want to
see the files causing this trouble, I have put the source code for
Averager.h and Averager.m
http://lark.cc.ku.edu/~pauljohn/Swarm/Averager.h
http://lark.cc.ku.edu/~pauljohn/Swarm/Averager.m
In the for loop above, we are trying to speedup iteration over a
collection. We do not get the compiler warning if we write the for loop
with less optimization. "iter" is an index object for a collection, it
answers to "next" and "getLoc". We iterate with
for (obj= [iter next]; [iter getLoc]==Member; obj=[iter next])
That does not generate any trouble in gcc 3.2, but it is slower because
the methods "next" and "getLoc" have to be looked up on every iteration.
We have in the past been accelerating this by caching the methods like
so:
In the header file, we declare:
id (*nextImp) (id, SEL);
id (*getLocImp) (id, SEL);
The macros NEXT and GETLOC call functions nextImp and getLocImp
#define NEXT(index) nextImp(index, M(next))
#define GETLOC(index) ((id) getLocImp (index, M(getLoc)))
And before NEXT or GETLOC are used, we grab the selectors like so:
(IMP) nextImp = [protoIndex methodFor: M(next)];
(IMP) getLocImp = [protoIndex methodFor: M(getLoc)];
In the Swarm libraries, M() is another macro:
#define M(messageName) @selector (messageName)
So, if you know whether there is a way I should rewrite the Averager
class, let me know. If you think it is a gcc bug, let me know.
Thanks very much
--
Paul E. Johnson email: pauljohn@ukans.edu
Dept. of Political Science http://lark.cc.ku.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700