c - Left shift of negative values by 0 positions? -


in c, left shift of negative value undefined behavior. i've encountered 2 libraries compiled intel's icc offending code removed. same code fine under clang, comeau, gcc , msvc.

does standard make mention of left shifting negative value 0 places? undefined?

(the detail i'm curious 0-sized shift, no shift @ in practice. i'm wondering if language vague such 0-sized left shift may allowed).

excerpt c99 technical corrigenda tc1, tc2, , tc3 included:

6.5.7 bitwise shift operators

[...]

the integer promotions performed on each of operands. type of result of promoted left operand. if value of right operand negative or greater or equal width of promoted left operand, behavior undefined.
result of e1 << e2 e1 left-shifted e2 bit positions; vacated bits filled zeros. if e1 has unsigned type, value of result e1 × 2e2, reduced modulo 1 more maximum value representable in result type. if e1 has signed type , nonnegative value, , e1 × 2e2 representable in result type, resulting value; otherwise, behavior undefined.

so, undefined.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -