[comp.sys.next] NeXT C compiler bug in 0.8 system software

louie@trantor.umd.edu (Louis A. Mamakos) (04/05/89)

The following program will fail to produde the correct result, and will
emit the "Can't convert unsigned long to double" message on the NeXT.  It
works just fine on various platforms, including MicroVAX running 4.3BSD
tahoe with either the standard PCC based C compiler, or the GNU CC 1.34.

#include <stdio.h>

main()
{
	double dbl = 1024.0 * 1024.0 * 1024.0;	/* 2^30 */
	unsigned long ul = 3.0 * dbl;		/* between 2^31 and 2^32 */

	printf("3.0*1024.0*1024.0*1024.0 = 0x%08x\n", ul);

	if (ul != 0xc0000000) {
		printf("Can't convert unsigned long to double.\n");
		exit(1);
	}
	exit(0);
}

The correct result should be:

	3.0*1024.0*1024.0*1024.0 = 0xc0000000

while running it on the NeXT results in:

	3.0*1024.0*1024.0*1024.0 = 0xffffffff
	Can't convert unsigned long to double.

which is clearly bogus.  Running it with or without the -O option doesn't
seem to have any effect.



Louis A. Mamakos  WA3YMH    Internet: louie@TRANTOR.UMD.EDU
University of Maryland, Computer Science Center - Systems Programming