r/cprogramming • u/am_Snowie • Oct 16 '26
is doing ~INT_MAX undefined behavior?
/r/C_Programming/comments/1x7hxgd/is_doing_int_max_undefined_behavior/
5
Upvotes
r/cprogramming • u/am_Snowie • Oct 16 '26
View all comments
Show parent comment
1
u/flatfinger Oct 19 '26
The purpose of making C behave in quirky fashion when targeting arcane platforms wasn't to allow code for conventional platforms to be usable on such platforms, but rather to allow people familiar with C to program platforms that couldn't write less than 16 bits at a time, or that used ones'-complement arithmetic to write in "C, but with 16-bit 'char'" or "C, but with ones'-complement arithmetic" rather than having to learn a whole new language or force compilers for unusual architectures to generate nasty inefficient machine code that tried to emulate more common machines.
The notion of "portability" should be recognized as encompassing two notions that are often incompatible with each other:
Debugging can be facilitated if code is known never to do weird things with addressing, but sometimes code that does weird things with addressing can do things faster than would otherwise be possible. It used to be understood that a programmer would know better than anyone else what balance between each kind of portability, performance, speed of writing, ease of reading, and ease of troubleshooting should best be struck for the task at hand.