Fwd: Obj-C language question: C function within @implementation
Fwd: Obj-C language question: C function within @implementation
- Subject: Fwd: Obj-C language question: C function within @implementation
- From: publiclook <email@hidden>
- Date: Thu, 3 Jul 2003 19:00:35 -0400
Begin forwarded message:
From: publiclook <email@hidden>
Date: Thu Jul 3, 2003 12:00:20 PM US/Eastern
To: "Sean McBride" <email@hidden>
Subject: Re: Obj-C language question: C function within @implementation
You are describing the normal and expected behavior of Objective-C.
By implementing a function within the implementation of a class, you
give the function the same access rights as an instance method
implemented in the same context. This might be considered similar to
a C++ friend function. I suppose the rationale' may be that if you
have access to the source code of an implementation than you can make
any changes you want so why not allow it...
http://cocoa.mamasam.com/MACOSXDEV/2002/02/2/26736.php
http://cocoa.mamasam.com/COCOADEV/2002/05/2/35472.php
Note from the Objective-C grammar:
class-implementation:
@implementation class-name [ : superclass-name ]
[ instance-variables ]
[ implementation-definition-list ]
@end
implementation-definition-list:
function-definition
declaration
method-definition
implementation-definition-list function-definition
implementation-definition-list declaration
implementation-definition-list method-definition
You see that a class-implementation consists of @implementation
followed by an optional colon and superclass name followed by optional
instance variable declarations followed by an optional implementation
definition list followed by @end.
The implementation-definition-list may consist of any number of
function definitions, declarations, and method definitions in any
order.
On Thursday, July 3, 2003, at 09:44 AM, Sean McBride wrote:
I'm no Obj-C expert, but I found some suspicious code that my Obj-C
newbie coworker wrote. I've reduced it to this example:
#import <Cocoa/Cocoa.h>
int main(int argc, const char *argv[])
{
return NSApplicationMain(argc, argv);
}
@interface MyClass : NSObject
{
IBOutlet NSProgressIndicator* progress;
}
@end
@implementation MyClass
void Function (void* thing)
{
MyClass* uc = (MyClass*)thing;
[uc->progress stopAnimation:uc];
}
@end
Notice that there is a C function within the @implementation block.
This
compiles without error/warning with gcc and CodeWarrior. If I move
this
outside the @implementation block CW gives an error and gcc gives a
warning (progress is protected), both of which make more sense IMHO.
Should this code compile as it is above? Seems to me progress is
protected no matter where Function() is.
Thanks!
--
____________________________________________________________
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.
_______________________________________________
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.