Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site randvax.ARPA Path: utzoo!linus!philabs!seismo!hao!hplabs!sdcrdcf!randvax!obrien From: obrien@randvax.ARPA (Michael O'Brien) Newsgroups: net.lang.c Subject: problem in type conversion Message-ID: <1603@randvax.ARPA> Date: Fri, 30-Dec-83 20:20:11 EST Article-I.D.: randvax.1603 Posted: Fri Dec 30 20:20:11 1983 Date-Received: Mon, 2-Jan-84 02:33:57 EST Organization: Rand Corp., Santa Monica Lines: 31 We think there may be a serious problem with type conversion. Consider the following program: int i = 6, j = 6; main() { i *= .5; j = j * .5; printf ("%d, %d\n", i, j); } This program will show i = 0 and j = 3. The problem is that the ".5" in the first line is converted to an integer before the multiplication takes place, and in the second line, the multiplication is done in double precision before the integer conversion occurs. This seems to violate Kernighan and Ritchie, which states that E1 op= E2 may be regarded as identical to E1 = E1 op (E2); when E1 and E2 are of arithmetic type, except that E1 is evaluated only once in the first case. That single difference does not seem to imply such an egregious difference in type conversion. We see this both in 4.1 and 4.2 BSD PCC, and in the Ritchie compiler for V7 on the PDP-11. We don't have System III or System V compilers handy. Any comments?