3 ms·
Multi character constants is one of the many things in C that would be nice to use if the language would just choose some well-defined behaviour for it. It does
by jonathrg 2y ago
Multi character constants is one of the many things in C that would be nice to use if the language would just choose some well-defined behaviour for it. It doesn't really matter which.
- mananaysiempre 2y agoMainstream compilers agree on multicharacter literals being big endian; that is, 'AB' is usually 'A' << CHAR_BIT | 'B'. The exception is MSVC, which also works like that as long as you don't use character escapes, but if you do it emits some sort of illogical, undocumented mess that looks like an ancient implementation bug fossilized into a compatibility constraint.
- poincaredisk 2y agoYour phrasing is a bit confusing. Multicharacter litersl being big endian (as you've defined it) means that it'll actually end up little-endian in memory (in little endian architectures, like x86). So 'ABCD' will end up as 'DCBA' in memory. Really interesting to hear about the escaping quirk, I need to test it.