Greenhills "C" compiler (casting int's)

David R. Trinidad drt at cysog.UUCP
Thu Jun 6 07:21:46 AEST 1991


1. I just received a reply from the Greenhills people on the
following code .. which compiles and runs correctly on AT&T,
mircosoft, borland and SCO:

#include <stdio.h>
#include <limits.h>
int intermediate = 100;
main()
{
	if (intermediate > USI_MAX -1 ) printf("this is a bug");
	if ((unsigned)intermediate > USI_MAX -1 ) printf("this works");
}

2. The response from GREENHILLS:
If a operand is unsined int , the second is converted in unsigned
int (sic).
If an operand is int the second is converted in int (signed)
[(sic)]
To get a correct value you must cast the first value to unsigned.

3. AT&T .... promotes the first value to unsigned if the second
operator is unsigned therfore correctly comparing the if
statment.

4. The question is : What is the standard ? K+R, and ANSI
Direct answers to either this posting or preferably E-MAIL
below.

************************************************************************
Organization: 	Cycare Systems 
Internet : 	drt%cysog at hbiso.ma02.bull.com
UUNET:		uunet!hbiso!cysog!drt
Phone:		(602) 224 0555	| FAX: (602) 224 0872
System:		B.O.S. UNIX     |
	 UNIX isn't just an OS  | It's a way of life !!!!!
***********************************************************************



More information about the Comp.std.c mailing list