This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Question for ISO C standards gurus
- From: "Dave Korn" <dk at artimi dot com>
- To: <gcc at gcc dot gnu dot org>
- Date: Mon, 29 Mar 2004 11:29:04 +0100
- Subject: RE: Question for ISO C standards gurus
> -----Original Message-----
> From: gcc-owner Behalf Of Ian Lance Taylor
> Sent: 27 March 2004 01:26
> Diego Novillo writes:
>
> > On Thu, 2004-03-25 at 13:08, Dave Korn wrote:
> >
> > > "Here is the complete list of all sequence points in C++:
[...snip...]
> > > after the evaluation of all function arguments in a function call
> > > and before execution of any expressions in the function body
[...snip...]
> > So, the program below should print 5? It certainly doesn't
> with gcc
> > 3.2 nor mainline:
> >
> > int foo (int x)
> > {
> > return x;
> > }
> >
> > main ()
> > {
> > int *p;
> > int a[2];
> > a[0] = 4;
> > a[1] = 5;
> > p = a;
> > printf ("%d\n", foo (*p++));
> > }
> >
> > It will print 5 if I use pre-increment on 'p', which is what I
> > would've expected (I'm no language lawyer, though).
>
> I can't see any reason why that would print 5. Based on the
> above, p should be incremented before the function call to
> foo(). But that doesn't change the value of *p++, which
> means "get the value at *p, then increment p". The above
> just means that this should not happen:
> t1 = *p;
> foo (t1);
> p = p + 1;
> (at least, it should not be possible to observe that that
> happened; in the above program, p, as a local variable whose
> address is not taken, probably could be incremented after the
> function call, since there is no way for anything to detect
> when the increment occurred.)
>
> Ian
Indeed, that's my understanding as well. I'd also mention that if foo was a
nested function and had access from its inner scope to the value of *p in
the enclosing function, it should be 5 at the time control flow was in foo.
cheers,
DaveK
--
Can't think of a witty .sigline today....