#define many times without #undef,is it legal?

后端 未结 4 839
你的背包
你的背包 2020-12-21 20:22

For example, I define AA for three times, is it legal?:

#include
#define AA 10
#define AA 20
#define AA 30
int main() {
    printf(\"         


        
4条回答
  •  有刺的猬
    2020-12-21 20:46

    No it is not. The C standard clearly states that it is a constraint violation, 6.10.3 p.2:

    An identifier currently defined as an object-like macro shall not be redefined by another #define preprocessing directive unless the second definition is an object-like macro definition and the two replacement lists are identical.

    So as for all constraint violations, your compiler is only obliged to issue a "diagnostic" that is an explanatory message. It may or may not continue to compile your code.

    To state it more directly, your code erroneous and your compiler must tell you.

提交回复
热议问题