|
Message-ID: <1437159779.30461.1.camel@inria.fr>
Date: Fri, 17 Jul 2015 21:02:59 +0200
From: Jens Gustedt <jens.gustedt@...ia.fr>
To: musl@...ts.openwall.com
Subject: Re: Left-shift of negative number
Hello,
Am Freitag, den 17.07.2015, 18:28 +0000 schrieb Loïc Runarvot:
> According to the C11 standard, doing a left-shift on a negative
> integer is considered as an undefined behavior (6.5.7:4).
There is no such thing as "considered undefined behavior", this is a
terminology that makes not much sense. Unfortunately the term
"undefined behavior" is often used as a synonym for "errorneous code"
which it just isn't.
Effectively, the C standard at the place that you cite doesn't define
a behavior for such shifts of negative values. But this doesn't mean
that a particular implementation of a C compiler or the C library
(here musl) can't define a behavior for that.
What worries me more than the shift of a negative value, is that this
code is erroneous if `int` is only 16 bit wide. Whereas we can
reasonably assume that a shift of a negative value in two's complement
is the same as an unsigned shift, compilers tend to produce just crap
if the shift exceeds the width.
So I would feel much more comfortable if we'd use UINT32_C(0x40)
inside the R macro.
Jens
--
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536 ::
:: :::::::::::::::::::::: gsm France : +33 651400183 ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::
Download attachment "signature.asc" of type "application/pgp-signature" (182 bytes)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.