21 ms·
You're straw-manning a bit with your "3rd smallest type available." Int was supposed to be the natural word-size for the system, which, despite C being "portabl
by Zanni 3y ago
You're straw-manning a bit with your "3rd smallest type available." Int was supposed to be the natural word-size for the system, which, despite C being "portable," you had to know for efficiency reasons. Memory access at the time was slow, and if you specified an Int that you couldn't load/unload with a single instruction or fit into a register, you would kill your performance.
- chihuahua 3y agoThanks for the response. On one hand, it makes sense that the natural word size is relevant. On the other hand, that means it encourages writing non-portable code.
- jcranmer 3y ago> Memory access at the time was slow Actually, memory access was fast (assuming you're referring to the time when C was developed, not when ANSI C was standardized), as you could access any individual memory location in a single clock cycle. It's once you start seeing the development of RISC systems that being able to clock processors faster than memory starts becoming a thing, and that makes memory slow. > and if you specified an Int that you couldn't load/unload with a single instruction or fit into a register, you would kill your performance. This is the bigger issue. If you have to do lots of extra masking or adjustment of the values to emulate an N-bit integer that isn't otherwise available on your system, that's the slowdown.
- Dylan16807 3y agoInt in particular has that use. But there isn't a similar value in char and short and long being variable, so I wouldn't say it's a strawman. And int has stopped being a reliable machine word size, if it ever was reliable in the first place. Edit: I would say the most useful sizes are fixed_width and max(fixed_width, machine_word). And none of the native C types reliably fit into either of those categories.