Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site yale-comix.UUCP Path: utzoo!watmath!clyde!burl!ulysses!harpo!decvax!yale-comix!leichter From: leichter@yale-comix.UUCP (Jerry Leichter) Newsgroups: net.lang.c Subject: C portability test Message-ID: <3474@yale-comix.UUCP> Date: Fri, 20-Apr-84 15:31:01 EST Article-I.D.: yale-com.3474 Posted: Fri Apr 20 15:31:01 1984 Date-Received: Sat, 21-Apr-84 02:37:42 EST Organization: Yale University CS Dept., New Haven CT Lines: 93 Brian Jones (drutx!qwerty) presents a program to test C compilers for proper evaluation of expressions involving side-effects and coercions. I've tried his sample program on two more C compilers, with the following results: VAX11-C (VMS) DECUS C (VMS, compatibility mode) ------------- --------------------------------- 20 2 20 2 20 3 0 3 30 5 30 5 30 6 33 6 The VAX11-C results are identical to those Brian found for "Unix on a Dec 11/70, Ver. 3.0"; he believes this is the (a?) "right answer". (I'm not questioning his judgement; I haven't looked at the code closely enough to form any sort of opinion.) The DECUS C results - which would be the same on all the operating systems and machines (VAXes and 11's) DECUS C runs under - are identical to what Brian found for "Mark Williams Co. C on an Intel 86/330 System, with 8087 support". I find this an interesting statement, since I think the same person (Dave Conroy) did most of both compilers. DECUS C required two changes to the code as distributed. The first is a known DECUS C restriction: Local variables cannot be initialized. This required that j in main be initialized in a separate statement. The second is either a bug or a change in the language definition (DECUS C pre-dates K&R): DECUS C requires a parenthesized expression after return; this requires that: return a; in ifunc() be changed to: return (a); For people who might have missed the original article and want to try this test out on their favorite compiler, here is the version I used, with the edits for DECUS C in place (might help on other old compilers): /* * Simple E1 op= E2 test */ #include main() { int i, j, *ifunc(); j = 0; i = 100; *ifunc(&i, &j) = *ifunc(&i, &j) * .2; printf("%d %d\n", i, j); i = 100; *ifunc(&i, &j) *= .2; printf("%d %d\n", i, j); i = 100; *ifunc(&i, &j) = *ifunc(&i, &j) / 3.3; printf("%d %d\n", i, j); i = 100; *ifunc(&i, &j) /= 3.3; printf("%d %d\n", i, j); } int *ifunc(a, b) int *a, *b; { ++*b; return (a); } Brian's results, in summary: 1 2 3 4 5 6 ---- ---- ---- ---- ---- ---- 19 2 20 2 20 2 20 2 20 2 19 2 0 3 0 3 20 3 20 4 0 3 19 4 30 5 30 5 30 5 30 6 30 5 30 5 33 6 33 6 30 6 30 8 33 6 30 6 1) Maxi-Unix on an Ahmdahl (sp?), Ver. 5.0 2) Unix on a Vax 11/780, Ver. 5.0 3) Unix on a Dec 11/70, Ver. 3.0 **right answer** 4) Unix on a 3B20, Ver. 5.0 5) Mark Williams Co. C on an Intel 86/330 System, with 8087 support 6) Ancient Yourdon (I think) compiler on a Dec 11/44 **right answer** -- Jerry decvax!yale-comix!leichter leichter@yale