This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: negating unsigned longs in conditional expressions
- To: leo at dachau dot marco dot de (Matthias Pfaller)
- Subject: Re: negating unsigned longs in conditional expressions
- From: Jeffrey A Law <law at upchuck dot cygnus dot com>
- Date: Wed, 24 Mar 1999 22:54:20 -0700
- cc: egcs-bugs at egcs dot cygnus dot com
- Reply-To: law at cygnus dot com
In message <m10P4GB-003wXtC@troja.dachau.marco.de>you write:
> Hi,
>
> I have tried this small test program on arm32, sparc and i386 (machine
> specifications are at the end of my posting).
>
> #include <stdio.h>
>
> int
> main(int argc, char **argv)
> {
> unsigned long ul;
> long l1, l2;
>
> if (argc != 2)
> exit(1);
>
> ul = atoi(argv[1]);
> l1 = ((long)ul < 0) ? -ul : ul;
>
> if ((long)ul < 0)
> l2 = -ul;
> else
> l2 = ul;
>
> printf("%08lx %08lx\n", l1, l2);
> exit(0);
> }
>
> In all cases I get
>
> $ gcc -o tst tst.c
> $ tst -1000
> fffffc18 000003e8
>
> With our old gcc (2.7.2.1) I get "000003e8 000003e8". Is this a bug, or
> does my program trigger some unspecified C behaviour?
An FYI -- I tried this with the egcs development sources and I got
000003e8 000003e8.
jeff