Re: Obj-C language question: C function within @implementation
Re: Obj-C language question: C function within @implementation
- Subject: Re: Obj-C language question: C function within @implementation
- From: "Sean McBride" <email@hidden>
- Date: Thu, 3 Jul 2003 11:15:49 -0400
- Organization: Matrox Electronic Systems Ltd.
Jeff Harrell (email@hidden) wrote on Thu, 3 Jul 2003 09:10:47 -0500:
>
I've never seen anything quite like that. I can't tell what the intent
>
is; is that supposed to be a class or an instance function? Since it
>
casts the argument to an instance pointer, I'm going to assume that
>
it's supposed to be an instance method.
The code is quite obviously awful and useless. It is merely a small
example illustrating what might be a compiler bug. But I'm not an Obj-C
expert so I wanted to check here. The real code was something like: 1)
in an Obj-C method create a pthread, passing it a C function pointer and
the 'self' of the calling class. 2) in the pthread function, use a cast
to get access to my Obj-C object 3) send a message to a protected member
of my object.
The error my coworker made (aside from step 3 itself :)) was to
accidentally put the C function within the @implementation block, and it
still compiles. I noticed this, and moved the C function out of the
@implementation block and it stopped compiling. I'm wondering if it
should never have compiled in the first place.
Here's the code again, with better names:
@interface MyController : NSObject
{
IBOutlet NSProgressIndicator* progressBar;
}
@end
@implementation MyController
void pthread_start_routine (void* arg)
{
MyController* controller = (MyController*)arg;
[controller->progressBar stopAnimation:controller];
}
@end
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Mac Software Designer +1-514-822-6000
Matrox Electronic Systems Ltd. Montrial, Quibec, Canada
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.