structure problem - error or warning?

Morris Keesan keesan at bbncca.ARPA
Sat Oct 13 08:43:10 AEST 1984


>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



More information about the Comp.lang.c mailing list