Whats the scope of c code within objective-c classes?

Posted by roja on Stack Overflow See other posts from Stack Overflow or by roja
Published on 2010-03-20T15:38:26Z Indexed on 2010/03/20 15:41 UTC
Read the original article Hit count: 352

Filed under:
|
|
|

I was reading up about bypassing objective-c's messaging to gain performance (irrelevant to this specific question) when i found an interesting bit of code:

#import <Cocoa/Cocoa.h>

@interface Fib : NSObject { }

- (long long) cFib: (NSUInteger) number;

@end

@implementation Fib

// c implementation of fib
long long cFibIMP(NSUInteger number)
{
  return (number < 3) ?
    1 :
    cFib(number - 1) + cFib(number - 2);
}

// method wrapper for c implementation of fib
- (long long) cFib: (NSUInteger) number
{
  return cFibIMP(number);
}

@end

My question is; when using c function, within an objective-c object, what scope is the c function (cFibIMP in this particular case) placed in? Does the objective-c class encapsulate the c function removing change of name-clash or is the c function simply dumped into the global scope of the whole objective-c program?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about c