Path: utzoo!utgpu!attcan!uunet!husc6!cmcl2!rutgers!ucsd!ucsdhub!hp-sdd!hplabs!hpda!hpcuhb!hpcllla!hpcllca!walter From: walter@hpcllca.HP.COM (Walter Murray) Newsgroups: comp.std.c Subject: Sequence points and order of evaluation Message-ID: <16490004@hpcllca.HP.COM> Date: 4 Aug 88 19:42:24 GMT Organization: HP NSG/ISD California Language Lab Lines: 44 First, a warm-up: int f(i) {printf ("%d",i); return i;} main () { (f(1)+f(2)) + (f(3)+f(4)); printf ("\n"); } 1. Is this a strictly conforming program? (I think NO, because it produces output dependent on an unspecified order of evaluation.) 2. Is a conforming implementation required to produce a diagnostic for this program? (I think NO, because the program doesn't violate a syntax rule or constraint.) 3. Is a conforming implementation even required to accept this program? (Technically, I think NO, because it's not a strictly conforming program.) 4. At execution, may a conforming implementation produce the output "1324" for this program? (I don't know. If it's not a strictly conforming program, does the dpANS impose any requirements at all on a conforming implementation?) Now for the real question: main () { int temp, result; result = (temp=1, temp) + (temp=2, temp); printf ("result = %d\n", result); } 5. Is this a strictly conforming program? 6. What output will this program produce on a conforming implementation? (I've tried it on six compilers from three vendors, and they all produce output which seems wrong to me.) (The second program was inspired by a posting to comp.lang.c by Jeffrey E. F. Friedl.) Walter Murray All opinions expressed here are my own.