Question

I'm trying to set a breakpoint in my objective c++ ( I think its called) code.

I've used #ifdef _cplusplus and #endif to wrap the code, but when I go to set a breakpoint in it, it breaks on the end of the method body, and none of the code in the body is run.

Bad breakpoints :/

I've simplified the code I had, but I expect at least to see numbers being printed in the console because of the cout.

The file has the extension .mm too. I'm new to mixing C++ and Objective-C. Anything I've missed?

Was it helpful?

Solution

#ifdef is a preprocessor directive - in short, this means that without _cplusplus being #defined somewhere, your debugger is smart enough to say Hey, this is dead code - don't even try to debug it.

Preprocessor directives are lines included in the code of programs preceded by a hash sign (#). These lines are not program statements but directives for the preprocessor. The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements.

These preprocessor directives extend only across a single line of code. As soon as a newline character is found, the preprocessor directive is ends. No semicolon (;) is expected at the end of a preprocessor directive. The only way a preprocessor directive can extend through more than one line is by preceding the newline character at the end of the line by a backslash ().

These are super useful, and for a common example have a quick look at Include Guards. As a test to see what I mean, try adding #define _cplusplus directly above the #ifdef and try again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top