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
1
u/pskocik Oct 16 '26
Right-shifting negatives is implementation-defined (probably an arithmetic shift). Left-shifting negatives or left-shifting signed positives too into and beyond the sign bit is UB https://port70.net/~nsz/c/c11/n1570.html#6.5.7