0

I have a question about out commented code and couldn't find a good answer.

Does the compiler read out commented code, or does it immediately skip that code?

Max
  • 12,622
  • 16
  • 73
  • 101

4 Answers4

2

The compiler (like most compilers) immediately skips to the first non-commented line of code. A notable exception are the xml comments, used for the documentation if the compiler is running with some settings.

misleadingTitle
  • 657
  • 6
  • 21
2

It depends on the language.. in C++, for example, comments are processed and discarded by the preprocessor, and the compiler will not even see them.

In general, comments will not "consume memory" in the target executable. Lexers may or may not discard them right away, so they not even enter into the parsing phase of the compiler, but they do not go into the later phases of compilation.

EDIT: I have seen the C# and visual-studio tags too late...

  • csc: IIRC from the sscli source, comments are skipped directly by the lexer
  • visual studio (intellisense) it does NOT skip them immediately: it needs to process comments for coloring, regions, etc..
Lorenzo Dematté
  • 7,638
  • 3
  • 37
  • 77
0

No, it won't consume any space if you are talking about ordinary comments like // and /**/, simply because they don't any source code to be processed.
You won't find any comments in a compiled program. Have you ever tried to perform a syntax-error in a comment like

// object o = NEW object();

If the Compiler cared about this, it would have reported an error, but it won't!

Little reference here.

EDIT

There is an exception, though. If you want to transform your comments into an XML-file there is a /doc-Option for the compiler. See here.

Community
  • 1
  • 1
bash.d
  • 13,029
  • 3
  • 29
  • 42
0

The preprocessor, i.e. before actual compilation, the extra whitesace and comments are removed. so you don't really have to worry about the size of your code. Also, you don't have to worry about the long names of your variables coz they're gonna be given internal names.

kBisla
  • 590
  • 2
  • 8
  • 23