c - What is the value of number left shift by -1 -


this question has answer here:

what result of number when left shifted -1 in c programming using left shift operator?

e.g.:

23 << -1 

from c11 standard 6.5.7p3 (for former versions same):

"if value of right operand negative or greater or equal width of promoted left operand, behavior undefined."

iow: undefined behaviour. prepare nasal demons.

briefly: do not

caution: while many programmers aware of , avoid negative shift counts, ignored counts >= bit-size of value undefined. makes ((unsigned int)1 << 32) - 1 undefined if unsigned int has 32 bits or less. signed values things become more complicated due sign (thanks @chux pointing me @ that). common pitfall. implementations, different results constant expressions (compile-time evaluated) , run-time evaluation might occur.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -