Why does the preprocessor directive in one function affect the compilation of another?

前端 未结 3 2086
温柔的废话
温柔的废话 2021-01-20 01:03

Following program compiles successfully and print 1000 without even calling a foo() function from our main() function. How is it p

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 01:06

    The #define is processed by the preprocessor before the compiler does anything. It is a simple text replacement. The preprocessor doesn't even know if the line of code is inside or outside a function, class or whatever [Ref: https://stackoverflow.com/a/36968600/5505997]. Clearly you do not need to call the function to set the value and obviously you will not get any error during compile.

提交回复
热议问题