Type of #define variables

后端 未结 7 2190
一个人的身影
一个人的身影 2020-11-27 17:33

If I have:

#define MAXLINE    5000

What type is MAXLINE understood to be? Should I assume it is an int? Can I test it somehow?

7条回答
  •  失恋的感觉
    2020-11-27 18:22

    It has no type. It's just a token which the preprocessor will put into the source code before passing the code to the compiler. You can do this (ridiculous) thing to declare a variable called x5000:

    #define APPEND(x,y) x ## y
    
    int main() {
            int APPEND(x,5000);
            x5000 = 3;
    }
    

    The preprocessor turns that into this before passing it the compiler proper:

    int main() {
            int x5000;
            x5000 = 3;
    }
    

    So, just because you see 5000 in a macro, it doesn't mean it needs to be numeric in any way.

提交回复
热议问题