Reputation: 171
I am new to programming with no formal programming training, so please excuse this newbie question. I can't seem to find a definitive answer on it, and need to be sure.
Here's the scenario: sometimes I need to try different lines of code to see if they work, but still want to keep the original lines in there in case the new lines don't work (or for future reference). I thought by putting // in front of the line I want to "comment out" would mean the line of code would be ignored when compiling the program, but my app crashed and pointed to a line I thought was commented out. I am using Xcode 4.
Is there another symbol I should be using to comment out lines or blocks of code? For example, will /* at the beginning and */ at the end accomplish this?
Upvotes: 2
Views: 200
Reputation: 1432
Also, make sure you do a clean build. It's possible that sometimes old object files are used and even though you commented out a line in the IDE, it may not have build with that updated file.
Upvotes: 2
Reputation: 89529
For "commenting out" big blocks of code, I do conditionals like:
#if I_AM_TESTING_SO_DONT_COMPILE_THIS
...
...
...
...
#endif // I_AM_TESTING_SO_DONT_COMPILE_THIS
And yes, the traditional C-style /*
and */
also work to "comment out" blocks of code.
The reason your compile crashed with //
is because while a single line gets commented out, you might have had some extra code on a second line.
Such as:
//NSString * someContentFromSomewhere = [[NSString alloc] initWithContentsOfURL:
[NSURL URLWithString: @"http://www.stackoverflow.com"]];
The first line is commented out. The second line is a syntax error.
Upvotes: 2