negating unsigned longs in conditional expressions
Jeffrey A Law
law@upchuck.cygnus.com
Wed Mar 31 23:54:00 GMT 1999
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
More information about the Gcc-bugs
mailing list