How does the C preprocessor handle circular dependencies?

前端 未结 5 1333
无人共我
无人共我 2021-02-01 11:59

I want to know how the C preprocessor handles circular dependencies (of #defines). This is my program:

#define ONE TWO 
#define TWO THREE
#defi         


        
5条回答
  •  無奈伤痛
    2021-02-01 12:39

    https://gcc.gnu.org/onlinedocs/cpp/Self-Referential-Macros.html#Self-Referential-Macros answers the question about self referential macros.

    The crux of the answer is that when the pre-processor finds self referential macros, it doesn't expand them at all.

    I suspect, the same logic is used to prevent expansion of circularly defined macros. Otherwise, the preprocessor will be in an infinite expansion.

提交回复
热议问题