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?
In general, how can one determine the type of #defineed variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It has no type. It is a simple text substitution. The text 5000 will be dropped in place wherever MAXLINE appears as a token.
For example:
will put the value 5000 in
a.While
will not result in
So, if you want type-checking, macro’s are not the way to go. You will want to declare static constants instead, that way type-checking is done by the compiler.
For information on the differences between
static,const, and#define, there are many sources, including this question: Static, define, and const in C