/*
#define FOO
*/
#ifdef FOO
#define BAR "pirate"
#else
#define BAR "ninja"
#endif
int main() { printf(BAR); getchar(); }
In this code FOO is not defined (Visual Studio 2008). I assume that comments are processed first, then preprocessor, and then code. Are comments always processed before the preprocessor? Is this part of a standard?
Removing comments : It removes all the comments. A comment is written only for the humans to understand the code. So, it is obvious that they are of no use to a machine. So, preprocessor removes all of them as they are not required in the execution and won't be executed as well.
Preprocessing is the first pass of any C compilation. It processes include-files, conditional compilation instructions and macros. Compilation is the second pass. It takes the output of the preprocessor, and the source code, and generates assembler source code.
What is the best way to comment out a section of code that contains comments? The other way to put comments in your program is to use the // symbol. Everything from the // symbol to the end of the current line is omitted from the compiled version of the program.
In computer science, a preprocessor (or precompiler) is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers.
I assume that comments are processed first, then preprocessor, and then code. Are comments always processed before the preprocessor?
Sort of -- part of the preprocessor's job is to remove comments. In this case, it doesn't care that you have the directive inside the comments; it's still removed just like any other comment.
According to the C standard, there are 8 translation phases during translation (compilation) of a program. Each comment is replaced by a whitespace character in translation phase 3, whereas preprocessing directives are executed in phase 4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With