Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile time operators in C

Tags:

c

compile-time

I'm familiar with only one compile time operator in C - sizeof. Are there any others that I as a programmer should be aware of?

like image 873
Manish Burman Avatar asked Jan 18 '23 17:01

Manish Burman


2 Answers

Only sizeof that I'm aware, although in C99 sizeof cannot be done at compile time for variable length arrays (VLAs).

like image 60
Nic Foster Avatar answered Jan 28 '23 11:01

Nic Foster


I think what you're grasping for but missing the terminology to describe is a constant expression or integer constant expression. The results of certain operators can be (integer) constant expressions if their operands are, and as you've pointed out, the result of sizeof can be even if its operand is not constant as long as it's not a VLA. See 6.6 in C99:

http://port70.net/~nsz/c/c99/n1256.html#6.6

like image 35
R.. GitHub STOP HELPING ICE Avatar answered Jan 28 '23 11:01

R.. GitHub STOP HELPING ICE