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]

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

On 17 Jun, 2004, at 19.08, Mark Mitchell wrote:

Ziemowit Laski wrote:

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?

In general, this code is unsafe.

Yes, it certainly _can_ be, but it's up to the user to ensure that the ABI gods are satisfied. After all, C is not a high-level, strongly-typed language... :-)
But, like I said, I only really care about my ObjC messaging casts getting through, while at the same time not causing havoc in the middle- and back-ends. :-)

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]