[comp.std.c] Do functions always return copies?

eggert@rise.twinsun.com (Paul Eggert) (10/12/89)

I thought that in a function yielding a non-void type T, the statement

	return E;

is equivalent to the statement

	{ T temp = (E);  return temp; }

But the following program has me wondering whether this is true in ANSI C.
With indirection() as defined below, shouldn't ``u.s2.s = indirection(&u.s1.s);''
yield a _copy_ of u.s1.s, and assign that copy to u.s2.s?  Because of the
implicit copy, doesn't this example satisfy the overlap restriction of pANS
3.3.16.1?

I'm asking because GCC disagrees with me on a Sun-3 unless I add the flag
-fpcc-struct-return; it outputs ``1, 65538, 131075, 196612 should be 1, 2, 3,
4'' instead of ``1, 2, 3, 4 should be 1, 2, 3, 4''.  Replacing ``return *p;''
as described above fixes the problem.  Shouldn't this be a bug in GCC?

union u {
	struct s1 {
		struct s {
			int i, j, k, l;
		} s;
		char c;
	} s1;
	struct s2 {
		char c;
		struct s s;
	} s2;
};

struct s indirection(p)
	struct s *p;
{
	return *p;
}

int main()
{
	union u u;
	u.s1.s.i = 1;
	u.s1.s.j = 2;
	u.s1.s.k = 3;
	u.s1.s.l = 4;
	u.s2.s = indirection(&u.s1.s);
	printf(
		"%d, %d, %d, %d should be 1, 2, 3, 4\n",
		u.s2.s.i, u.s2.s.j, u.s2.s.k, u.s2.s.l
	);
	return 0;
}