Comparison failure in C compiler

Richard Wolff rwolff at noao.UUCP
Thu Nov 29 02:07:04 AEST 1984


The following program (sadly) prints the message

main()
{
	int n, i;
	float x[2];

	x[0] = 1.;
	n = 10000;
	i = 0;
	if(x[i] > n)
		printf("finds %g  is > %d\n",x[i],n);
}

The relevant assembly code that implements the comparison is

	movl	-8(fp),r0
	cvtld	-4(fp),r2
	cvtfd	-16(fp)[r0],r1
	cmpd	r1,r2

The selection of "r1" is unfortunate.  The section of pcc/table.c
that seems to be at fault is

OPLOG,	FORCC,
	SAREG|AWD,	TFLOAT,
	SAREG|AWD,	TDOUBLE,
		2*NAREG,	RESCC,
		"	cvtfd	AL,A1\n	cmpd	A1,AR\nZP",

Changing A1 to A2 solves the problem.  But, is this a correct
solution, and is it the best one?

-- 
Richard Wolff, National Optical Astronomy Observatories, Tucson, AZ
Usenet:   {allegra,arizona,astrovax,decvax,hao,ihnp4}  !noao!rwolff
Arpa:     noao!rwolff at lbl-csam



More information about the Comp.lang.c mailing list