Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA Path: utzoo!linus!bbncca!keesan From: keesan@bbncca.ARPA (Morris Keesan) Newsgroups: net.lang.c Subject: Re: structure problem - error or warning? Message-ID: <1014@bbncca.ARPA> Date: Fri, 12-Oct-84 18:43:10 EDT Article-I.D.: bbncca.1014 Posted: Fri Oct 12 18:43:10 1984 Date-Received: Sat, 13-Oct-84 02:16:21 EDT References: <564@ccice5.UUCP> Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 42 >Why does the C compiler only give a warning instead of an error on the >use of an illegal structure member. The following code example demonstrates >what I mean: > >main() > { > struct v { > int w; > }; > > struct x { > int y; > } z; > > z.w = 0; > } > >The C compiler gives the warning "illegal member use: w" on the line >z.w = 0. It seems to me that this should be an error. Is this a bug >in the C compiler? Thanks in advance for any answers that you can provide. >-- > > Jim Roche > Computer Consoles Inc. Well, it depends on what you mean by "the C compiler". It obviously boils down to a question of which C compiler you're using, and what version of the language it purports to compile. Kernighan & Ritchie C explicitly allows this member use, which is in no way illegal (Section 14.1 of the reference manual: "In fact, any lvalue is allowed before ., and that lvalue is then assumed to have the form of the structure of which the name on the right is a member."). The System V Release 1 version of the language changes this behaviour, and explicitly promises to give messages of the type you cite. From the System V "User Level Changes to the C Language" (in the "Transition Aids" document): "Prior to the language change these references [of the 'z.w' type] were considered legitimate. However with the current release of PCC these will produce non-fatal error messages." -- Morris M. Keesan {decvax,linus,ihnp4,wivax,wjh12,ima}!bbncca!keesan keesan @ BBN-UNIX.ARPA