Working of the C Preprocessor

前端 未结 7 892
轻奢々
轻奢々 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:35

    This simple replacement (first b with a and then a with 170) should work with any compiler. You should be careful with more complicated cases (usually involving stringification '#' and token concatenation '##') as there are corner case handled differently at least by MSVC and gcc.

    In doubt, you can always check the ISO standard (a draft is available online) to see how things are supposed to work :). Section 6.10.3 is the most relevant in your case.

提交回复
热议问题