问题
A few questions about the C++ preprocessor:
- how to make the preprocessor go to a new line into the preprocessoring code?
- how to make the preprocessor insert a tab character or multiple spaces into the preprocessoring code?
- how to make the preprocessor insert comments into the preprocessoring code?
回答1:
1) use the backslash, as Tim pointed out
2) I don't think you can
3)
#define COMMENT /##/ this is a comment
#define CPPCOMMENT(c) /##/ c
#define CCOMMENT(c) /##* c *##/
COMMENT
CPPCOMMENT(This is a c++ comment)
CCOMMENT(This is a c comment)
Edit
2 Caveats
1) Doesn't work in all compilers.
2) Don't do this, it's stupid.
回答2:
Regarding #3, it's the preprocessor's responsibility to remove comments from the code, I don't think it's allowed to leave them in. In any case this would be a flag specific to the C++ compiler you're using so you should specify your environment.
回答3:
Questions 2) and 3) don't make much sense, as other people have outlined.
As for question 1, I assume what you mean is multi-line macros, which can be done in this way:
#define FOO line 1 \
line 2 \
line 3 \
... \
line n
Note the missing \
at the last line!
回答4:
how to make the preprocessor go to a new line into the preprocessoring code?
Why?
how to make the preprocessor insert a tab character or multiple spaces into the preprocessoring code?
Why?
how to make the preprocessor insert comments into the preprocessoring code?
Why?
The preprocessor is a pre processor, it runs before the code is converted into machine code. The whitespace and comments you want to add will have no effect on output of the application.
If you're trying to control the output of gcc -E
, or something similar then you're barking up the wrong tree.
回答5:
You are doing it wrong... PREPROCESSOR is not for that purpose.
来源:https://stackoverflow.com/questions/4007865/few-questions-about-the-c-preprocessor