Re: Union nested in structure.

From: Dave Thompson (david.thompson1_at_worldnet.att.net)
Date: 02/14/05


Date: Mon, 14 Feb 2005 09:46:38 GMT

On 9 Feb 2005 20:36:47 GMT, mwojcik@newsguy.com (Michael Wojcik)
wrote:
<snip>
> Because that's how the committee thought it should work, and not
> specifying the tag scope rules would have been a Bad Thing.
>
> (And, IIRC, the single global-scope tag namespace existed in pre-
> standard C as well, so they're preserving existing practice. What
> did change was the separation of members into their own scoped
> namespace. Or was it that members had their own namespace, but it
> had global scope? Or was there only a single namespace for tags,
> members, and ordinary identifiers? I no longer have a pre-standard
> K&R to consult.)
>
*Very* early C had one namespace for (names of) members of all structs
-- or at least all structs at (what we now call) file scope, I don't
recall if there were struct definitions within a function/block at all
-- and you could apply member names "of" (from) any struct as members
of any (other) struct, with often wrong results. This is why the API
structs that survive from early Unix like tm (tm_year, tm_mon etc.)
and <not standard C> stat (st_mode, st_mtime etc.) have the struct
encoded in the member names to ensure they don't conflict. I'm pretty
sure that even then members were isolated from ordinary identifiers
and tags; and that members became per-struct even before K&R1 much
less the standard, though I also no longer have a 1ed to check.

- David.Thompson1 at worldnet.att.net



Relevant Pages

  • Re: scope and linkage rule, very confusing!
    ... different definitions in the same scope and in the same name space. ... Struct, union and enum tags. ... Tag and member names are in scope wherever the struct/union/enum ...
    (comp.lang.c)
  • Re: K&R p 130
    ... Outside main, "struct point" has no meaning, so the definition is ... programmer...if I can call myself that :-)) are able to declare. ... separate translation units are compatible if their tags and members ... Because you were concentrating on scope, ...
    (comp.lang.c)
  • Re: Structure size directives
    ... When you target a specific architecture, the alignment requirements are know apriori, so system developers do make use of explicit alignment and knows what they are doing. ... struct foo obj; ... offset of 4 bytes, and with the #pragma pack, it would be allocated at ... There are really two different cases here, you talk about the usage of "pack" to minimize padding in a struct, while I talk about the "pack " usage, which specify alignmentof struct members. ...
    (comp.lang.c)
  • Re: procedure parameter struct order
    ... the members of this struct would always have the same order on ... >> members in the order they are declared. ... Or if there even is a stack as such, ... > compiler would be quite correct if, behind the scenes, all it pushed on ...
    (comp.lang.c)
  • Re: Uninitialized memory, malloc and unsigned char
    ... the structure or union object may be a trap representation. ... I think this ensures that the holes between sturct members do not ... affect validity of the struct. ...
    (comp.std.c)