& operator

smh at mit-eddie.UUCP smh at mit-eddie.UUCP
Mon Dec 5 02:47:56 AEST 1983


		char *in;
		char *out;
		out = &(*in++);
	Should "out" be set to "in" or "in + 1?"

Upon consideration of the types during the evaluation of the
right-hand-side, it seems clear that:
	- the & operator is applied to the value of the expression
	  inside the parentheses;
	- that value is type char, and that char is the one pointed
	  to by the original value of in;
	- the address of that character has type (char *) and indeed
	  is the original value of in.
Therefore, the code example ought to be equivalent to:
	out = in;
	*in++;
The dereferencing of pointer (the '*') seems nugatory, but may have
side effects such as causing a segmentation violation or accessing
a device register.

	Different compilers seem to have different opinions.  I believe
	it should be set to "in."

If this analysis is correct, which are the compilers with a different
opinion?  It would be nice to know!

Steve Haflich, MIT Experimental Music Studio



More information about the Comp.lang.c mailing list