[Bug c/15506] New: wrong cast from long to long long

ken dot tsukahara at tmt-d dot co dot jp gcc-bugzilla@gcc.gnu.org
Tue May 18 16:17:00 GMT 2004


on x86 family(32bit) Linux
RedHat9 : GCC 3.2.2, 3.2.3
SUSE9 : GCC 3.3.1, 3.4.1

A long long value which is casted from a long value (< 0) seems to be wrong.

$ cat longlong.c

#include <stdio.h>
int main(int argc, char **argv)
{
    long long     ll = 0xc0000000;
    unsigned long ul = 0xc0000000;
    long          sl = 0xc0000000;

    printf("long long : 0x%llx\n", ll);
    printf("u_long    : 0x%lx\n",  ul);
    printf("long      : 0x%lx\n",  sl);
    printf("u_long -> long long : 0x%llx\n", (long long)ul);
    printf("long   -> long long : 0x%llx\n", (long long)sl);

    return 0;
}

$ cc -o longlong longlong.c
$ ./longlong
long long : 0xc0000000
u_long    : 0xc0000000
long      : 0xc0000000
u_long -> long long : 0xc0000000
long   -> long long : 0xffffffffc0000000

-- 
           Summary: wrong cast from long to long long
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P1
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ken dot tsukahara at tmt-d dot co dot jp
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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



More information about the Gcc-bugs mailing list