public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/34235]  New: short variable cast to unsigned int fails to right shift as unsigned
@ 2007-11-26 13:09 fgccbz1 at greynode dot net
  2007-11-26 13:43 ` [Bug c/34235] " rguenth at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: fgccbz1 at greynode dot net @ 2007-11-26 13:09 UTC (permalink / raw)
  To: gcc-bugs

Shifting the result of a cast does not produce the same results as when using
an intermediate variable.

        short x = -1;
        unsigned a = ((unsigned)(short)-1) >> 1;
        unsigned tmp = (unsigned)x;
        unsigned b = tmp >> 1;
        unsigned c = ((unsigned)x) >> 1;
        printf("a:%x b:%x c:%x",a,b,c);

produces
a:7fffffff b:7fffffff c:ffffffff

while I'd expect the result for c to be the same as the other two.

Similar behavior appears to occur with other types, as long as the source type
is shorter than the target type and the target type is int or longer.


-- 
           Summary: short variable cast to unsigned int fails to right shift
                    as unsigned
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fgccbz1 at greynode dot net
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34235


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-01-26 13:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-26 13:09 [Bug c/34235] New: short variable cast to unsigned int fails to right shift as unsigned fgccbz1 at greynode dot net
2007-11-26 13:43 ` [Bug c/34235] " rguenth at gcc dot gnu dot org
2007-11-27 12:08 ` fgccbz1 at greynode dot net
2007-11-27 12:09 ` fgccbz1 at greynode dot net
2007-11-27 12:12 ` fgccbz1 at greynode dot net
2007-12-02 22:33 ` pinskia at gcc dot gnu dot org
2008-01-25 23:17 ` [Bug c++/34235] " rguenth at gcc dot gnu dot org
2008-01-25 23:20 ` rguenth at gcc dot gnu dot org
2008-01-25 23:24 ` rguenth at gcc dot gnu dot org
2008-01-25 23:36 ` rguenth at gcc dot gnu dot org
2008-01-26 11:36 ` rguenth at gcc dot gnu dot org
2008-01-26 11:37 ` rguenth at gcc dot gnu dot org
2008-01-26 14:06 ` fgccbz1 at greynode dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).