Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!sri-unix!sri-spam!robert From: robert@sri-spam.istc.sri.com (Robert Allen) Newsgroups: comp.lang.c Subject: C struct definition according to K & R. Message-ID: <9929@sri-spam.istc.sri.com> Date: Tue, 10-Mar-87 13:31:59 EST Article-I.D.: sri-spam.9929 Posted: Tue Mar 10 13:31:59 1987 Date-Received: Wed, 11-Mar-87 03:49:28 EST Organization: SRI International, Menlo Park, CA Lines: 58 Keywords: May structs have similar member names in dissimilar order? 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@spam.istc.sri.com ---------------------------------------------------------