_cmd value inside c functions

wh1t3cat1k picture wh1t3cat1k · Dec 11, 2010 · Viewed 12k times · Source

What's the value of _cmd variable when I access it from C-style function's body?

Is it defined inside selectors (Objective-C) methods only?

P.S.

This question may originate from my non-understanding of what _cmd is. I would greatly appreciate if someone provided me with a good explanation source.

Answer

Abhilash Reddy Kallepu picture Abhilash Reddy Kallepu · May 5, 2014

The major use of the _cmd function is to get the method name in which it is called.

The use of the _cmd with some other functions has been written below.

NSLog(@"<%@:%@:%d>", NSStringFromClass([self class]), NSStringFromSelector(_cmd), __LINE__);

Instead of above line you can also use PrettyFunction

NSLog(@"%s", __PRETTY_FUNCTION__);