Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!sri-spam!mordor!styx!lll-lcc!pyramid!voder!blia!ted From: ted@blia.UUCP Newsgroups: comp.lang.c Subject: DEC VAX C Message-ID: <1708@blia.BLI.COM> Date: Tue, 24-Feb-87 14:22:13 EST Article-I.D.: blia.1708 Posted: Tue Feb 24 14:22:13 1987 Date-Received: Fri, 27-Feb-87 04:14:01 EST Organization: Britton Lee, Los Gatos, CA Lines: 33 Keywords: VMS, C, differences between versions, missing cast 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@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.