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.

2
  • 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" Commented Jun 15, 2012 at 14:57
  • I had the impression LINE was for the input file, I will try that Commented Jun 15, 2012 at 15:02

2 Answers 2

3

Here you are a little piece of useful code:

#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.