Code: Select all
const uint16_t c = 0xffffu;
uint16_t y = c + 1u;
For the record, different compilers appear to take different approaches as to whether or not a const-qualified variable meets the definition of a "constant expression".
Moderators: misra-c, david ward
Code: Select all
const uint16_t c = 0xffffu;
uint16_t y = c + 1u;
Code: Select all
const uint16_t c = 0xffffu;
uint16_t y = c + 1u;
Code: Select all
uint16_t c = 0xffffu;
uint16_t y = c + 1u;
Code: Select all
const int *p = &i;
Should readThis rule does not apply to the expression c + 1 in the following compliant example as it accesses an object and therefore does not satisfy the constraints for a constant expression
This rule does not apply to the expression c + 1 in the following compliant example as it accesses an object and therefore does not satisfy the semantics for a constant expression
Should readThis rule applies to expressions that satisfy the constraints for a constant expression, whether or not they appear in a context that requires a constant expression.
This rule applies to expressions that satisfy the constraints and semantics for a constant expression, whether or not they appear in a context that requires a constant expression.