-1

I just came across this line of code where a method is being instantiated without the use of either + or -. Can you please explain the code :

void *ABCD(NSString *xyz)
2
  • 11
    Aww. This is a C function. You know what's scary? People who don't even recognize basic C language constructs are trying to write iOS apps. That's scary. I suggest you take a step back, do yourself a favor and learn C before trying to continue iOS development. Don't do more than you can do at once, learn in small steps. Start here, you won't regret it.
    – user529758
    Jul 18, 2013 at 6:44
  • 2
    You might be interested in buying and reading All the C You Need to Know by Bill Dudney. iPad only. Written for Objective-C developers. Jul 18, 2013 at 7:04

2 Answers 2

6

That is a C function, of the type

 return_type  method_name (argument_list)

Your function returns a void * , a generic pointer, and takes an NSString arguement.

2
  • 3
    @Spectravideo328 Nah. It's Objective-C. C is a subset of Objective-C, so you can use C functions in Objective-C code. (After all, that's what the runtime does when it fools you into using nice methods and all that OO stuff.)
    – user529758
    Jul 18, 2013 at 7:18
  • Yeah, I got that part. It just creeped me out to see an objective C type in the argument list of a C function! Jul 18, 2013 at 7:20
0

With a semicolon at the end, it's a C function declaration. If you follow the spiral rule for C declarations:

What is ABCD? ABCDis a function that takes a pointer to an NSString and returns a pointer to void. (ie. a pointer to elements of any data type).

Knowing the spiral rule is useful because C function declarations can be very complex.

Not the answer you're looking for? Browse other questions tagged or ask your own question.