Question

Are comments in a c source file removed by the compiler (for example visual c++ and GCC)?

/* ... */

// ...
Was it helpful?

Solution

The compiler uses different steps to translate the sourcecode to machine readable code.

The first step, the lexical analysis phase translates the characters to tokens. A token can be an identifier, a literal value, a reserved word, or an operator.

Comments and whitespace are mostly ignored during this phase. They are only used to separate different tokens.

In the next steps, there is no concept for a comment or a whitespace, so yes, they are removed while compiling.

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