Re: shift+test optimization error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/01/2017 09:03, leon zadorin wrote:

> Last time I checked in C, as well as in C++, standards -- shifting by
> the number of bits greater *or equal* to the size of the type is
> undefined behavior...
> 
> e.g. something like "An expression is shifted by a negative number or
> by an amount greater than or equal to the width of the promoted
> expression (6.5.7)." from
> https://www.securecoding.cert.org/confluence/display/c/CC.+Undefined+Behavior#CC.UndefinedBehavior-ub_51
> 
> The exact place in C++14 and or latest C standards escape me right
> now, but the thesis of this UB stands correct I think...

In C11, it's 6.5.7p3

http://port70.net/~nsz/c/c11/n1570.html#6.5.7p3

> The integer promotions are performed on each of the operands. The
> type of the result is that of the promoted left operand. If the value
> of the right operand is negative or is greater than or equal to the
> width of the promoted left operand, the behavior is undefined.

C11: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
C99: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

http://port70.net/~nsz/c/c11/
http://port70.net/~nsz/c/c99/

> what is sizeof(long) on your target?

Sane 64-bit platforms define sizeof(long) to 8
Win64 defines sizeof(long) to 4 /troll

I think most (if not all) gcc ports define CHAR_BIT to 8.

Regards.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux