0

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)
alex
  • 479,566
  • 201
  • 878
  • 984
Amitabha
  • 1,664
  • 1
  • 12
  • 30
  • 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](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list), you won't regret it. –  Jul 18 '13 at 06:44
  • 2
    You might be interested in buying and reading [All the C You Need to Know by Bill Dudney](https://itunes.apple.com/us/book/all-the-c-you-need-to-know/id581989356?mt=11). iPad only. Written for Objective-C developers. – Matthias Bauch Jul 18 '13 at 07:04

2 Answers2

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.

Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
  • 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.) –  Jul 18 '13 at 07: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! – Khaled Barazi Jul 18 '13 at 07: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.

Daniel Martín
  • 7,815
  • 1
  • 29
  • 34