lkml.org 
[lkml]   [2008]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: C language lawyers needed
Roland Dreier wrote:
>
> A fairly small test case that I don't understand either is:
>
> unsigned foo(int x)
> {
> return (((x & 0xffffff) | (1 << 30)) & 0xff000000) >> 24;
> }
>
> just running "gcc -c" (ie no extra warnings enabled) on that produces
> the same:
>
> b.c: In function 'foo':
> b.c:3: warning: integer overflow in expression
>
> I'm sure there's some promotion rule or something that makes sense of
> this, but it's a mystery to me...
>

Looks like a gcc bug to me.

0xff000000 is unsigned, like any hexadecimal constant.

unsigned foo(int x)
{
return ((x & 0xffffff) | (1 << 30)) & 0x80000000;
}

... is enough to reproduce the bug -- explicitly casting either side or
both of the & operator to unsigned doesn't affect the warning, either.

-hpa


\
 
 \ /
  Last update: 2008-08-28 00:03    [W:0.046 / U:0.824 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site