gcc - How to create a "C single-line comment" macro -


I am trying to create a "single line comment" macro in C , its use conditional According to some global macro definitions, this is the only idea to comment on lines of code.

This code is trying multiple passages, I get the error message from the compiler.

For example, directly following code sample from that page:

  define # comment slash (/) #define SLASH (s) / # # S #define DEBUG_ONLY COMMENT DEBUG_ONLY a = b; // & lt; - line # 83   

GCC returns the following error:

prog.c: 83: 1: error: pasting "/" and "/" some Does not give a valid preprocessing token
prog.c: 83: error: expected expression / ???? Token

As I mentioned, I played with that subject and tried many forms but failed to give all the same diagnosis.

What am I doing, and why does the code compile well from the article?

This does not work because the language specification does not allow it. In fact, by removing the comment, the first macro replacement occurs after the comments are removed, // is not a valid token (such as an error message). This macro can not be generated by the replacement, and it does not mean "comment" anymore.

This standard is the "translation step" section numbering is different, but all C89, C99 and C11 defined in step 3:

each comment replaced with a space character is done.

and then in step 4:

Macro inventions are expanded

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -