Here is a general trick used to determine endianness at runtime, for example in the C FAQ :
int x = 1; if (*(char *)&x == 1) { } else { }
According to my reading of the standard, this does not lead to undefined behavior, since it does not violate the strict anti-aliasing rule.
In any case, if an integer type other than unsigned char can contain bits of additions (for example, x ), can the condition *(char *)x == 1 be satisfied, even if it is a little-individual system?
In this case, is it better to make a decision with the unions?
source share