🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2572

Re: Function Argument Evaluation

#2572
From: Stephen Clamage
Date: Thu, 21 Mar 1991 18:07
27 lines
1377 bytes
jdp@polstra.UUCP (John Polstra) writes:

|    #include <stdio.h>
|    int x = 100, y = 200, *p;
|    main() {
|	printf("%d %d\n", *(p = &x), *(p = &y));
|    }

|Could a conforming compiler translate this in such a way that the output
|of the program is "200 200"?
|I believe it could, based on this quote from section 3.3.2.2 of the
|October 31, 1988 draft:

|    The order of evaluation of the function designator, the arguments,
|    and subexpressions within the arguments is unspecified, but there is
|    a sequence point before the actual call.

The statement is identical in the final standard, and is the reason
why your example shows a legal result.  Legal results from this
example are
200 200 with evaluation order p=&x p=&y push(*p) push(*p)
100 100 with evaluation order p=&y p=&x push(*p) push(*p)
100 200 with evaluation order p=&x push(*p) p=&y push(*p)
200 100 with evaluation order p=&y push(*p) p=&x push(*p)
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Technical Details
Message-ID: <630@taumet.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!taumet!steve
References: <7621@polstra.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!taumet!steve
From: steve@taumet.com (Stephen Clamage)
Newsgroups: comp.std.c
Subject: Re: Function Argument Evaluation
Message-ID: <630@taumet.com>
Date: 21 Mar 91 18:07:36 GMT
References: <7621@polstra.UUCP>
Organization: Taumetric Corporation, San Diego
Lines: 27