'struct' - declarations & parameters

Dave Decot decot at cwruecmp.UUCP
Wed Feb 22 12:33:57 AEST 1984


Chris Torek says:

    ...writing

	struct { int i, j, k; } foo = { 1, 2, 3 };

	main () { printf ("%d %d %d\n", foo); }

    is just plain illegal.
    
This code is NOT illegal, nor is it illegal to pass unions.  It is only
non-portable (but lint(1) has no complaint, because the problem is in
printf).  In fact, it usually works (for example, on our VAX, 4.1bsd).  Some
recent changes to C allow you to pass structures and unions as parameters to
functions.  If your compiler has no `enum' types, then it is outdated, and
probably doesn't support struct/union parameter passing.

    As to whether the trailing semicolon is required in structure
    declarations:  all I can say is it doesn't hurt to use it.  (Though
    if you want type declarations to match function declarations, it
    should be optional.  I don't have to write "dummy () { ; }".)

It isn't, and should not be, optional.  The VAX compiler doesn't signal this
as a syntax error, but it should, since it is.  The fact that you need no
semicolon in a dummy function body is no demonstration of inconsistency,
it is a demonstration of consistency.  Statements in C are *terminated*
(not separated, as in Pascal) by a semicolon.  It is only natural that every
declaration (including field declarations) must also be terminated by a
semicolon.

The function body in

    dummy () { ; } 

is allowed and interpreted as a null statement, but in

    dummy () { }

there is no statement (since none are required), and thus no ; is needed.

Dave Decot		 "Non-Americans are people, too."
decvax!cwruecmp!decot    (Decot.Case at rand-relay)



More information about the Comp.lang.c mailing list