Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I comment out this string?

I'm unable to comment-out and compile the following line of code with /* */, within the XCode editor. I distilled this example down from a more complex string used in an XPath query:

the string itself seems fine:

NSString* s = @"//*//";

won't compile for me:

/*
NSString* s = @"//*//";
*/

XCode 4.4. I'll file a radar if anyone can confirm I'm not being stupid.

EDIT: nice to see that the SO syntax highlighter also exhibits an issue with this...

EDIT: okay, I filed a bug report with Apple. Thanks.

EDIT: Per Rob's answer below, this is NOT a bug :) Thanks for explaining it, Rob; totally makes sense now.

like image 949
TomSwift Avatar asked Sep 06 '12 22:09

TomSwift


People also ask

How do you comment out a block of text?

Comment and uncomment blocks of codePress Ctrl+Shift+/ .

How do you comment on a string?

A comment is a sequence of characters (on one or more lines) delimited by /* and */ . Within these delimiters any characters are allowed. Comments can contain other comments, as long as each begins and ends with the necessary delimiters.

How do you comment out a block of text in Python?

The most common way to comment out a block of code in Python is using the # character. Any line of code starting with # in Python is treated as a comment and gets ignored by the compiler.


1 Answers

This is not a compiler bug. The double-quote character " has no special meaning inside a comment, so the preprocessor doesn't pay any attention to it. The preprocessor just ends the comment as soon as it sees the */ characters.

The best way to comment out a section of code is to put // at the beginning of each line. A // comment ends at the next newline. Xcode has a menu command (shortcut: ⌘/) that will comment or uncomment your selected lines by inserting or removing // at the start of each line.

like image 163
rob mayoff Avatar answered Sep 28 '22 03:09

rob mayoff