mod.std.c Digest V6#2

Orlando Sotomayor-Diaz osd7 at homxa.UUCP
Sat May 4 02:13:30 AEST 1985


From: Orlando Sotomayor-Diaz (The Moderator) <cbosgd!std-c>


mod.std.c Digest            Fri,  3 May 85       Volume 6 : Issue   2 

Today's Topics:
       Are empty structures/arrays legal in the ANSI standard?
                         why not #endif blah?
----------------------------------------------------------------------

Date: Tue, 30 Apr 85 02:57:08 pdt
From: sun!gnu (John Gilmore)
Subject: Are empty structures/arrays legal in the ANSI standard?
To: std-c at cbosgd

I just tried to define a structure like this:

/*
 * Empty now but will have error code later.
 */
struct scparam {
};

The first error I got was a syntax error on the "}".  C accepts empty
braces in other places, why should I need a null statement here?  (A
simple ";" null statement didn't work, I needed to say "int;" to get
past this point.)

The second error was "zero sized structure".  I see nothing wrong with
a zero sized structure.  This is probably because I come from an APL 
background where empty arrays are not treated specially.  Is there a
particular reason that empty structures (or arrays) are a bad idea in C,
and does a compiler that disallows them follow the standard?

An empty array e.g. "int array[0];" produced a warning "zero or
negative subscript".  I've seen situations described on the net where
this would be useful, e.g. a variable-length string on the end of a
structure which is a symbol table entry.  Will this compiler
restriction make its way into the standard?

This was on Sun's 68000 pcc-based compiler.

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

Date: Fri, 3 May 85 00:48:43 edt
From: sfbc!lr
Subject: why not #endif blah?
To: std-c at cbosgd

Why not allow "#else blah" or "#endif blah"?  For the same reason that
we don't allow "break blah;" or "continue blah;" in the program text.

Just because there's no semantics for a particular locution isn't
reason enough to allow arbitrary garbage where no token is specified by
the grammar.  That's what comments are for.

Where would you like to be told you wrote "#else if test" by mistake
instead of "#elif test"?  That's what syntactic analysis is for.

Seriously, the Committee did not feel that the existence of programs
that misguidedly used an undocumented syntactic loophole in an
undocumented preprocessor justified legitimizing the practice.  As
always, if enough members can be persuaded the other way, this decision
can be reversed.

Larry Rosler, Chair, Language Subcommittee, X3J11

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

End of mod.std.c Digest - Fri,  3 May 85 12:11:34 EDT
******************************
USENET -> posting only through cbosgd!std-c.
ARPA -> ... through cbosgd!std-c at BERKELEY.ARPA (NOT to INFO-C)
In all cases, you may also reply to the author(s) above.



More information about the Mod.std.c mailing list