I think the problem with C is that it was originally designed for machines that aren't relevant anymore.
Back in the days of C being invented, memory was word-addressed. Integers smaller than a word had to be implemented by bit manipulation. C was very much defined so that int could be a word, so programs using int got good performance.
On modern architectures, there isn't really a single defined "word size", pretty much all the integer sizes up to 64-bit are the same performance, with the main performance differences between integers being memory reads/writes and how many you can fit in a packed SIMD register. So compiler authors just map char, short, int, long, and long long in a way that gives access to all the different supported sizes.
If you look at modern systems languages (Rust, Zig, etc), you'll notice that they use integer names like u32 or i64. In fact, the stdint.h header (added in C99 and C++11) defines fixed-width integers in C and C++ (e.g, uint32_t, int64_t, etc), and some coding standards for C and C++ mandate the use of fixed-width integers.
View all comments
Show parent comment
2
u/TDplay Jul 22 '24
I think the problem with C is that it was originally designed for machines that aren't relevant anymore.
Back in the days of C being invented, memory was word-addressed. Integers smaller than a word had to be implemented by bit manipulation. C was very much defined so that
intcould be a word, so programs usingintgot good performance.On modern architectures, there isn't really a single defined "word size", pretty much all the integer sizes up to 64-bit are the same performance, with the main performance differences between integers being memory reads/writes and how many you can fit in a packed SIMD register. So compiler authors just map
char,short,int,long, andlong longin a way that gives access to all the different supported sizes.If you look at modern systems languages (Rust, Zig, etc), you'll notice that they use integer names like
u32ori64. In fact, thestdint.hheader (added in C99 and C++11) defines fixed-width integers in C and C++ (e.g,uint32_t,int64_t, etc), and some coding standards for C and C++ mandate the use of fixed-width integers.