& operator in &(*in++).

jas at druxy.UUCP jas at druxy.UUCP
Sun Dec 18 11:35:05 AEST 1983


Re:	I would have to disagree with chris as to what should be assigned by:
		char *in, *out, buf[];
		in = buf;
		out = &(*in++);
	since he forgot the parentheses.  Given the parentheses, out SHOULD
	be set buf+1; that is, 'in' is incremented BEFORE the & operator is
	applied.

		-- Dave Olson (fortune!olson)

Dave, I believe you are mistaken.  Perhaps we can finally set this question
to rest by explicitly listing the order of operations when evaluating
&(*in++):

1.  Evaluate 'in'.
2.  Increment 'in'.  This is a side effect, which does not affect the
    evaluation of the expression &(*in++).
3.  Dereference the value produced by step 1.  The result is an lvalue
    of type char (I am using 'lvalue' as defined by Kernighan and Richie
    in section 5 of Appendix A of *The C Programming Language*).  The
    value of this result is the character pointed to by 'in' before
    incrementing, i.e., buf[ 0 ].
4.  Take the address of the value produced by step 3.  The result has
    type 'pointer to char' (or 'char *', if you prefer); its value is
    &buf[ 0 ], or buf.

Step 2 seems to be the only real bone of contention.  Section 7.2 of
Appendix A of *The C Programming Language* states:  "When postfix ++
is applied to an lvalue, the result is *the value of the object referred
to by the lvalue*.  *After* the result is noted, the object is
incremented...." (my emphasis).  I see no ambiguity in this sentence.

In my opinion, this subject has now been beaten to death, so here's
hoping I've just had the last word ( :-) ).

                           -- Jim Shankland
			      ihnp4!druxy!jas



More information about the Comp.lang.c mailing list