This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why does casting a function generate a run-time abort?

Compiling the following snippet

  typedef struct objc_Object * foo_id ;
  typedef struct blortstruct *blort ;
  extern foo_id objc_msgSend(foo_id, ...);

int main(int argc, char * argv[])
blort foo = 0, bar = 0 ;
foo_id obj0;
obj0 = ((foo_id ((*)(foo_id, char *, blort, blort))) &objc_msgSend) (obj0, "foo message", foo, bar);
return 0;

on the current TOT produces the following messages:

  R3692996.c: In function `main':
  R3692996.c:9: warning: function called through a non-compatible type
  R3692996.c:9: note: if this code is reached, the program will abort

Could someone shed some light on this? As some of you probably know, Objective-C and Objective-C++
relies on exactly this casting idiom for messaging. Currently, Objective-C receives special absolution
of sorts (i.e., compiling the above with '-x objective-c' will not produce the messages above), but then the
gimplifier and inliner conspire to create a temporary variable holding the function address ('&objc_msgSend'
in the above example), which leads to unacceptable code bloat.

So, could someone give me some pointers (no pun intended) on how to make the casting of functions
into a first-class citizen in the eyes of the back-end? I don't care if the pure C case continues to
produce the enigmatic warning above, but I would like the ObjC case to work and work well. :-)

Thanks in advance,

Ziemowit Laski                 1 Infinite Loop, MS 301-2K
Mac OS X Compiler Group        Cupertino, CA USA  95014-2083
Apple Computer, Inc.           +1.408.974.6229  Fax .5477

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]