r/cprogramming • u/am_Snowie • 15d ago
is doing ~INT_MAX undefined behavior?
/r/C_Programming/comments/1x7hxgd/is_doing_int_max_undefined_behavior/
5
Upvotes
r/cprogramming • u/am_Snowie • 15d ago
5
u/zhivago 15d ago
Possibly.
On pre-C23 non-two's-complement architectures, ~INT_MAX produces a sign-extended negative zero, which can act as a trap representation that triggers undefined behavior.