...
This noncompliant solution attempts to modify a variable's value as part of the _Generic
association list. The user may have expected the value of a
to be 2
because the type of the variable is int
, but because _Generic
does not evaluate its operands, the result is undefined behaviorthe value of a
is not modified.
Code Block | ||||
---|---|---|---|---|
| ||||
#define S(val) _Generic(val, int : val = 2, \ short : val = 3, \ default : val = 1) void func(void) { int a = 0; S(a); } |
...
This noncompliant code example attempts to modify a variable while getting its default alignment value. The user may have expected val
to be incremented as part of the _Alignof
expression, but because _Alignof
does not evaluate its operand, the result val
is undefined behaviorunchanged.
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stddef.h> void func(void) { int val = 0; /* ... */ size_t align = _Alignof(++val); /* ... */ } |
...