Re: Union nested in structure.

From: Michael Wojcik (mwojcik_at_newsguy.com)
Date: 02/09/05


Date: 9 Feb 2005 20:36:47 GMT


In article <1107961540.328230.287510@f14g2000cwb.googlegroups.com>, "Tapeesh" <tapeesh@gmail.com> writes:

I see Chuck Falconer has already posted explaining why you should
(properly) quote text you are replying to, and how to do so correctly
with the braindead Google Groups interface. I won't repeat those
instructions, but I urge you to take them to heart.

> But why does C standard demand such a behaviour?

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.)

> C is very particular about scope.

With good reason. That does not mean, however, that the scoping
rules are or should be the same for all namespaces.

> Why is that scope rules are not followed in case of
> structures, unions and enums?

They are. They're just different for the tag namespaces.

The only reason to put a tag on a struct (or union) is to make it a
distinct type. You can leave the tags off structs (or unions) if
they don't need to be treated as distinct types. Often that's the
case when you're defining one struct inside another; otherwise, why
not define the inner one separately, first, to show that it may be
used on its own?

-- 
Michael Wojcik                  michael.wojcik@microfocus.com
It does basically make you look fat and naked - but you see all this stuff.
   -- Susan Hallowell, TSA Security Lab Director, on "backscatter" scanners


Relevant Pages