[net.lang.c] inconsistency in C manual

henry@utzoo.UUCP (Henry Spencer) (03/11/84)

There is an inconsistency of a somewhat annoying nature between the
V7 C Reference Manual / appendix to K+R and the V7 (at least) cc:
Hear ye section 7.1 of the manual:

	...A primary expression followed by a dot followed by an
	identifier is an expression.  *The first expression must be
	an lvalue naming a structure or union*...

Consider the following:

	struct foo { int bar; };

	extern struct foo f();

	g()
	{
		int x;

		x = f().bar;
	}

By the same section of the white book, a function call is *not* an
lvalue.  Yet the V7 compiler (and probably most compilers) takes this
program fragment without complaint.

Clearly the compilers are doing the right thing; picking out one field
of a structure returned value is a reasonable thing to do.  And clearly
the manual is out of date on this point, since structure returns were a
late addition to the language.  But how does one fix the manual to permit
this particular usage?  Any ideas?  Do any of the more recent C manuals
shed any light on this?  (We have the System V distribution but it's not
where I can get at it quickly.)
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry

keesan@bbncca.ARPA (Morris Keesan) (03/20/84)

----------------------------

    The C Language section of the System V Programming Guide corrects the
incosistency introduced into the manual in V7 by the addition of functions
returning structs and unions.  From the Guide, under "EXPRESSIONS/A"

	A primary expression followed by a dot followed by an identifier is an
    expression.  The first expression must be a structure or a union, and the
    identifier must name a member of the structure or union.  The value is the
    named member of the structure or union, and it is an lvalue if the first
    expression is an lvalue.

Also, from the System V Transition Aids,

    3.2 Access to a Member of a Returned Structure or Union.

    Now that the language allows structure and union assignments a bug was
    uncovered in the compiler regarding the immediate access of members of the
    returned structure or union.

    An example of such a construct is:

	x = f().a;

    where f() is a function returning a structure that has a member element of
    "a".

    This bug has been identified and removed from the compiler.


Does anybody have any idea what the referred-to bug is?
-- 
					Morris M. Keesan
					{decvax,linus,wjh12,ima}!bbncca!keesan
					keesan @ BBN-UNIX.ARPA

chris@umcp-cs.UUCP (03/20/84)

Probably the bug referred to is the one where the compiler prints
"structure reference must be addressible" instead of compiling the
code.  Running the following through 4.1BSD PCC:

    struct xxx { int i, j; };
    struct xxx foo ();
    main () {
	register k = foo () . j;
    }

yields:

, line 4: structure reference must be addressable
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris.umcp-cs@CSNet-Relay