Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site ism780c.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!hplabs!sdcrdcf!ism780c!tim From: tim@ism780c.UUCP (Tim Smith) Newsgroups: net.lang.c Subject: Re: A simple non-portable expression tha Message-ID: <1709@ism780c.UUCP> Date: Tue, 15-Apr-86 16:21:30 EST Article-I.D.: ism780c.1709 Posted: Tue Apr 15 16:21:30 1986 Date-Received: Thu, 17-Apr-86 05:29:12 EST References: <1368@ism780c.UUCP> <32700003@siemens.UUCP> Reply-To: tim@ism780c.UUCP (Tim Smith) Organization: Interactive Systems Corp., Santa Monica, CA Lines: 24 In article <32700003@siemens.UUCP> jrv@siemens.UUCP writes: >>If R and L are longs, and i is an int, then the expression >> >> L = R + 2 + i; >> >>is non-portable. Lint, however, does not complain about this. > >I must be missing something. Why is this non-portable? > Since + is associative and commutative, the compiler is free to re-order the expression. If you are on a machine where and int is shorter than a long, and if the compiler decided to do the 2+i first, you may get an overflow, whereas if the compiler does the R+2 first there is no problem. To make this expression portable, it needs to be L = R + 2 + (int)i; or L = R + 2L + i; -- Tim Smith sdcrdcf!ism780c!tim || ima!ism780!tim || ihnp4!cithep!tim