A strong answer
The C standard only guarantees minimum bit widths for fundamental types (int is at least 16 bits, long at least 32 bits). Across 64-bit operating systems, C uses different data models: 64-bit Linux and macOS use LP64 (int is 32-bit, long and pointers are 64-bit), whereas 64-bit Windows uses LLP64 (int and long are both 32-bit, and only long long and pointers are 64-bit). Whenever code serializes structs to disk, parses network headers, or computes cryptographic hashes, relying on long or int breaks portability. Including <stdint.h> (uint8_t, int32_t, uint64_t) guarantees exact bit widths everywhere, while size_t and uintptr_t are guaranteed to match the target platform's object size and pointer width.
A classic bug occurs when mixing signed and unsigned types of the same rank—such as comparing int x = -1; with unsigned int y = 1U; (or size_t). Under C's usual arithmetic conversions, when a signed integer is compared with an unsigned integer of equal or greater rank, the signed value is converted to unsigned by adding $2^N$. For 32-bit integers, -1 converts to UINT32_MAX (4,294,967,295), so the expression -1 < 1U evaluates to false (4294967295 < 1 is 0)!
What the interviewer is listening for
- Knows the difference between LP64 (Unix) and LLP64 (Windows) and why
<stdint.h>is mandatory for binary formats and hardware registers. - Explains C's integer promotion (types narrower than
intpromote toint) and usual arithmetic conversion rules (signed converts to unsigned when ranks match or unsigned is wider). - Uses
size_tfor byte counts and array lengths, while avoiding unsigned underflow in reverse loops.
Common mistakes
- Writing
for (size_t i = n - 1; i >= 0; i--), which never terminates becausesize_tis unsigned (0 - 1wraps around toSIZE_MAX, which is still>= 0). - Assuming
sizeof(long) == sizeof(void *)on all 64-bit platforms (false on 64-bit Windows). - Ignoring
-Wsign-comparewarnings when comparing a signed error-capable variable (ssize_torint) against an unsignedsize_tthreshold.