Working of the C Preprocessor

前端 未结 7 839
轻奢々
轻奢々 2021-01-19 05:12

How does the following piece of code work, in other words what is the algorithm of the C preprocessor? Does this work on all compilers?

#include 

        
7条回答
  •  暖寄归人
    2021-01-19 05:52

    It's at §6.10.3 (Macro Replacement):

    6.10.3.4 Rescanning and further replacement

    1) After all parameters in the replacement list have been substituted and # and ## processing has taken place, all placemarker preprocessing tokens are removed. Then, the resulting preprocessing token sequence is rescanned, along with all subsequent preprocessing tokens of the source file, for more macro names to replace.

    Further paragraphs state some complementary rules and exceptions, but this is basically it.

    Though it may violate some definitions of "single pass", it's very useful. Like the recursive preprocessing of included files (§5.1.1.2p4).

提交回复
热议问题