C struct definition according to K & R.
Robert Allen
robert at sri-spam.istc.sri.com
Wed Mar 11 04:31:59 AEST 1987
I have been programming in C for about 5 years, on DEC and Sun
C compilers for UNIX. Recently several persons stated a point
which I find difficult to believe, however this point has
also been brought up in. re. the ANSI C standard, and I would
apprecitate some opinions from netters.
According to "The Proposed ANSI C Language Standard, part 5" by
Rex Jaeschke in _Programmers_World_, Jan-Feb '87, the following
is true (I quote verbatim):
"K&R (page 197) says 'Two structures may share a common initial
sequence of members; that is, the same member may appear in
two different structures if it has the same type in both and
all previous members are the same in both. (Actually, the
compiler chekcs only that a name in two different structures
has the same type and offset in both, but if preceding members
differ the construction is nonportable.)'
This meant that the following declarations generated a syntax
error since i and l had different types and offsets.
struct s1 {
int i;
long l;
}
struct s2 {
long i;
int l;
}
"
My understanding of the pertinent K&R text is, simply, the opposite.
That you *may* have the above construct in C. I believe that the issue
was discussed in K&R for some unknown reason, possibly because a language
in use at the time the C spec was written (?) *did not* allow such naming
conventions. In short, I believe that K&R were saying, "while constructs
such as this (above) may cause problems in some languages, they don't in
C."
My question to the net is, do you believe that the above constructs are
strictly legal in K&R C, or do you believe they are illegal in K&R C.
I'm interested in the C aspect, not so much how a given compiler does
it (although that would be much appreciated). If you reply by mail or
on the net, please include the # of years you've been using C, and which
machines/compilers you use. Thanks!
--
---------------------------------------------------------
"Ohhhh, God hates me..."
"Hate 'em back, it works for me!"
"PUNTA, PUNTA, PUNTA!!"
Robert Allen,
robert at spam.istc.sri.com
---------------------------------------------------------
More information about the Comp.lang.c
mailing list