#if sizeof(int) != 4
/* do something */
Using sizeof inside #if doesn’t work while inside #define it works, why?
#define size(x) sizeof(x)/sizeof(x[0]) /*works*/
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.
Nothing is evil – everything can be misused, or in your case misunderstood. The
sizeofoperator is a compiler feature, but compiler features are not available to the preprocessor (which runs before the compiler gets involved), and so cannot be used in#ifpreprocessor directives.However, when you say:
and use it:
the preprocessor performs a textual substitution that is handed to the compiler: