This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

negating unsigned longs in conditional expressions


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?

Thank's - Matthias Pfaller

i386 (Linux)
	$ uname -a
	Linux troja 2.0.36 #9 Mit Mär 10 16:57:29 MET 1999 i586
	$ gcc -v
	Reading specs from /usr/arch/lib/gcc-lib/i586-linux/egcs-2.91.60/specs
	gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)

Sparc (SunOS4.1.4)
	$ uname -a
	SunOS ra 4.1.4 13 sun4m
	$ gcc -v
	Reading specs from /usr/arch/lib/gcc-lib/sparc-sunos4/egcs-2.91.60/specs
	gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)

arm32 (NetBSD)
	$ uname -a
	NetBSD lethe 1.3K NetBSD 1.3K (LETHE) #90: Fri Mar 19 23:26:36 CET 1999     leo@lethe:/usr/src/sys/arch/arm32/compile/LETHE arm32
	$ gcc -v
	Using builtin specs.
	gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
-- 
Matthias Pfaller                            Software Entwicklung
marco Systemanalyse und Entwicklung GmbH    Tel   +49 8131 5161-41
Hans-Böckler-Str. 2, D 85221 Dachau         Fax   +49 8131 5161-66
http://www.marco.de/                        Email leo@dachau.marco.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]