Quantcast
Channel: User CPlus - Programming Language Design and Implementation Stack Exchange
Viewing all articles
Browse latest Browse all 65

If size could be determined at compile time then why could size not be determined at preprocess time?

$
0
0

In C the sizeof() operator cannot be resolved in preprocessor conditions. If other operators such as + or - can be (so long as the operands are constants) then what is different about sizeof()?

What technical limitations prevent sizeof() from being resolved at preprocess time while other operators can be and what would it take for C to permit constructs such as the following?

#if sizeof(int) == 4// Code#endif

sizeof() is compile time constant but not preprocess time constant, hence the following is valid:

static char array[sizeof(int)];

If the compiler knows type sizes why can the preprocessor not?


Viewing all articles
Browse latest Browse all 65

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>