The C language requires that initializers for global variables be constant expressions. The motivation is for the compiler to evaluate the expression at compile time and write the calculated value to the generated object file.
Standard C provides specific rules for what is a constant expression:
- 117) , , ,
sizeof
, , _Alignof
, . Cast , sizeof
_Alignof
. - . , , :
, . , "abcd"[2]
.
:
- .
, , "abcd"[1]
, .
, . , ( , isConstantExpression
, , ).