0

Possible Duplicate:
How to print out the method name and line number and conditionally disable NSLog?
Using macro in Objective-C to log function name and line number

Question

What preprocessor directive or function call will help me identify what method is currently being called, or what line number is being executed in a file?

Background

I'm trying to write a quick macro to hunt down infinite loops, I want something that can be copy-pasted without modification, and will NSLog the current filename and line number, or current class and method name - really anything that will allow me to identify what loop is infinite.

Community
  • 1
  • 1
Alex Gosselin
  • 2,942
  • 21
  • 37
  • 1
    You have to agree that Objective-C is only sitting on top of C and every valid C program is a valid Objective-C program (exception to some recently added feature like dot notation for property) so `__LINE__` is a valid "meta-macro" – mathk Jun 15 '12 at 14:57
  • I had the impression __LINE__ was for the input file, I will try that – Alex Gosselin Jun 15 '12 at 15:02

2 Answers2

3

Here you are a little piece of useful code:

#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
Oleg Danu
  • 4,149
  • 4
  • 29
  • 47
0

You might be better off sticking with Xcode's built in static analysis. Running that will determine any unused variables, dead stores and most likely infinite loops. I'd assume that this will probably do a better job than writing your own custom implementation as the compiler is more aware of the possible uses of your code.

Zack Brown
  • 5,990
  • 2
  • 41
  • 54