On 2013-08-30 09:23, Dan Carpenter wrote:
On Thu, Aug 29, 2013 at 04:43:49PM +0000, Hartley Sweeten wrote:
You don't really need to test s->n_chan < 32. For s->n_chan >= 32,
s->io_bits will end up set to 0xffffffff anyway (and for s->n_chan > 32,
the low-level drivers shouldn't really be using s->state and s->io_bits
anyway).
I wasn't sure about that. 1 << 32 overflows the unsigned int to 0x100000000.
But I guess the 32-bit portion (0x00000000) - 1 is still 0xffffffff.
Nope. Shift wrapping doesn't work like that. Here is how it works in
GCC.
int maint(void)
{
int a, b, shift;
a = 1 << 32; /* a is zero */
shift = 32;
b = 1 << shift; /* b wraps to 1 */
printf("%x %x\n", a, b);
}
regards,
dan carpenter
Yes, you're correct, the standard says the behaviour is undefined.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@xxxxxxxxx> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel