3 ms·
> integer types have much clearer names now: uint8_t, uint16_t, int32_t etc… (these are not built-in but defined in the stdint.h header) The problems: 1. the
by WalterBright 4y ago
> integer types have much clearer names now: uint8_t, uint16_t, int32_t etc… (these are not built-in but defined in the stdint.h header)
The problems:
1. the C Standard Library doesn't use them
2. integer promotions rules still pertain to unsigned char, unsigned short, etc.
3. more generally, the language semantics are not defined in terms of those types
- nayuki 4y agoCorrect. For example, if int is a 32-bit type (as it commonly is), then uint16_t will be promoted to signed int, and (uint16_t)0xFFFF * (uint16_t)0xFFFF will cause signed overflow and trigger undefined behavior.
- xigoi 4y agoAlso, printf doesn't support them.
- gomijacogeo 4y agostdint.h includes definitions for format strings for printf/scanf-type functions (e.g. PRId64, ...) for all the new types. Using them is a bit clunky (e.g. printf("%"PRId64"\n",n);), but you get used to it.
- WalterBright 4y agoTrue, but "a bit clunky" is an understatement for how awful they look. I've never seen them used in the wild. I don't use them either. What I do use (since D supports calling C printf) is have the compiler check the format string against the types of the arguments. This means it won't compile if there's a mismatch. Many C compilers do this, too.