Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles $Revision: 1.6.2.16 $; site ISM780.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!gatech!seismo!harvard!talcott!panda!genrad!decvax!cca!ISM780!darryl From: darryl@ISM780.UUCP Newsgroups: net.lang.c Subject: YA Language Corner Message-ID: <30000020@ISM780.UUCP> Date: Wed, 30-Oct-85 21:22:00 EST Article-I.D.: ISM780.30000020 Posted: Wed Oct 30 21:22:00 1985 Date-Received: Sun, 24-Nov-85 03:41:00 EST Lines: 48 Nf-ID: #N:ISM780:30000020:000:2027 Nf-From: ISM780!darryl Oct 30 21:22:00 1985 Hello, all you budding language laywers out in netland! Today's topic is struct assignments. The question is, what do they mean? Consider the following code fragment: struct {int x;} foo, bar; f(){ int a,b,c; a = b * c + ( foo = bar ).x; } First off, is this even legal? Well, K&R doesn't discuss struct assignment, and I don't happen to have the "recent changes" with me. But, reading the April ANSI Draft, on page 29 we are told that the semantics of structure members are: " A postfix expression followed by a dot . and an identifier designates a member of a structure or union object. The first expression must evaluate to a structure or union object, and the identifier must name a member of that type object." Back on page 27, we learn that a postfix expression is defined as, amongst other things, a primary expression; in turn, a primary expression can be a parenthesized expression (page 26); an expression includes simple assignment. Page 37, under Assignment Operators, clearly states that "An assignment operator stores a value in the object specified by the lvalue. An assignment expression has the type of the left operand and the value of the left operand after the assignment." This says that the result of the struct assignment is a value that is a struct and has the value of foo. That satisfies the first clause above; the second is obviously fulfilled by x. Why do I bring this up? Well, a different arbiter, our PCC compiler, disagrees with my interpretation of the language. This is curious, because it allows constructs such as g( foo=bar ) and (with suitable declaration) h().x So, now you decide: Is it a bug? In the compiler or the example? Just another corner in the language, or obviously a legal construct? And how much would you enjoy porting legal ANSI C to your crufty old compiler? Cheers, --Darryl Richman, INTERACTIVE Systems Corp. ...!cca!ima!ism780!darryl The views expressed above are my opinions only.