DEC VAX C

ted at blia.UUCP ted at blia.UUCP
Wed Feb 25 05:22:13 AEST 1987


We have found a difference between the code generated by DEC VAX C versions
1.5 and 2.1. The C code that compiles to this is incorrect (missing a cast)
but none-the-less was in some of our code and the net result was code that
worked when compiled by 1.5 and didn't work when compiled by 2.1. I wanted
to share this with the net in case there is anyone else who has similar
code and will be bitten. If this has been discussed in the past, I apologize
for bringing it up again; we just recently found it.

The difference occurs when you compare an unsigned short against a negative
value without casting the short as a signed short. For example:
	unsigned short x;
	subroutine(&x);	/* subroutine writes back a value through the ptr */
	if (x < -10)	/* should read "if (((short) x) < -10)" */
Version 1.5 generates a CVTWL and a CMPL for the if and thus the value in
x is sign extended and everything works anyway. Version 2.1 generates a
MOVZWL instead of the CVTWL and so it isn't sign extended and the condition
is never true. (BTW, the reason this was in the code was that the value could
be interpreted as either signed or unsigned depending on other conditions.)

Anyway, let this be a warning. If you write improper C code (i.e. it passes
the DEC compiler but wouldn't have passed lint) and it works under the
current version of the DEC compiler, don't expect it to continue to work
under later versions.

===============================================================================
            Ted Marshall
            Britton Lee, Inc.
p-mail:     14600 Winchester Blvd, Los Gatos, Ca 95030
voice:      (408)378-7000
uucp:       ...!ucbvax!mtxinu!blia!ted
ARPA:       mtxinu!blia!ted at Berkeley.EDU
disclaimer: These opinions are my own and may not reflect those of my employer;
            I leave them alone and they leave me alone.



More information about the Comp.lang.c mailing list