r/C_Programming • u/am_Snowie • Oct 16 '26
Question is doing ~INT_MAX undefined behavior?
basically the title, i think producing INT_MIN by doing 1 << 31 is UB, so i thought of doing ~INT_MAX, but i am not sure if it's UB. sorry if it's dumb.
47
Upvotes
View all comments
Show parent comment
2
u/Iksfen Oct 16 '26 edited Oct 16 '26
If you are making an assumption that is not guaranteed by C standard it is technically UB. Whether you can accept that for your use case is a separate consideration
EDIT: to be more precise in this situation that would be Implementation Dependent Behavior not Undefined Behavior. The behaviour is defined for the 32bit int implementation.