Consider an expression *(1+\"AB\" \"CD\"+1)
What is the solution for this expression ? The above expression is a switch expression in C.
*(2
Here is a description of the different steps, all performed at compile time:
"AB" "CD"
is concatenated at compile time into a single string literal "ABCD"
.char
, initialized with the values 'A'
, 'B'
, 'C'
, 'D'
and '\0'
.1 + "ABCD" + 1
, the array decays into a pointer to its first element, said pointer is incremented by 2 to point to the third element, in this case the C
byte.char
value 'C'
.'C'
, converted to an int
, although it is not a constant expression as defined by the C Standard.switch
into a single call to printf
with the string "Casabance"
, as can be verified on http://gcc.godbolt.org/#Note that the prototype for main
in incorrect in your example, it should be int main(void)
or int main(int argc, char *argv[])
or equivalent. Furthermore, it is error prone to omit the break;
at the end of the last case
or default
clause in the switch
block.