Difficulty: Easy
Correct Answer: Yes — sizes vary by platform and ABI
Explanation:
Introduction / Context:
This question checks knowledge of the C data model and portability. Unlike types such as uint32_t from stdint.h, the fundamental integer types short and long have implementation-defined sizes subject to minimum ranges in the standard.
Given Data / Assumptions:
Concept / Approach:
The standard defines ranges, not fixed sizes. A short is at least 16 bits; a long is at least 32 bits and no smaller than an int. Therefore, both short and long can vary across compilers and architectures.
Step-by-Step Solution:
Identify data model: ILP32 (int, long, pointer are 32-bit), LP64 (long, pointer 64-bit), LLP64 (long long and pointer 64-bit; long 32-bit).Map consequences: short often 16 bits; long may be 32 or 64 bits.Conclude variability: neither short nor long has a universally fixed byte size.
Verification / Alternative check:
Printing sizeof(short) and sizeof(long) on different targets confirms differing values (e.g., 2/8 on LP64 vs 2/4 on LLP64).
Why Other Options Are Wrong:
Fixed by the standard: false; only minima and relations are fixed.Only long or only short varies: both can vary.Variation only on embedded: variation exists on desktops and servers too.
Common Pitfalls:
Coding with hard-coded sizes; failing to use stdint.h types when exact widths are required.
Final Answer:
Yes — sizes vary by platform and ABI
Discussion & Comments