r/transprogrammer • • Jul 16 '24

Javascript bad

Post image
104 Upvotes

35 comments sorted by

View all comments

Show parent comment

2

u/TDplay Jul 22 '24

i do have the same complaint about C and C++

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.

1

u/definitelynotagirl99 Jul 22 '24

i know why C is the way it is i was just making sure nobody would call me hypocritic or anything