I'm curious about this code:
int a = 'ftyp'; // a == 1718909296
int b = *((int*)"ftyp"); // b == 1887007846
My question: Why a != b ?
int a = 'ftyp'; // a == 1718909296
sets a
to the multi-character constant, which has implementation defined value. The value of a
is not defined by the standard. See Single quotes vs. double quotes in C or C++ for more details.
int b = *((int*)"ftyp"); // b == 1887007846
is cause for undefined behavior due to violation of strict aliasing.
The expectation that a == b
is ill founded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With