Topic: Speaking of warnings... (anon unions)


Author: usenet@phatbasset.com ("Hillel Y. Sims")
Date: Sat, 11 Jan 2003 18:53:51 +0000 (UTC)
Raw View
"Randy Maddox" <rmaddox@isicns.com> wrote in message
news:8c8b368d.0301090607.5dc9a484@posting.google.com...
> scottm@toast.net ("Scott Mayo") wrote in message
news:<3e1cd668$1@news.toast.net>...
> > I recently got a warning from a well known compiler which, while I'm
certain
> > had good grounding in the standard, I don't understand.
> >
> > I had an anonymous union of the form:
> >
> >     union {
> >         int a;
> >         float b;
> >         struct { ...structurestuffing...} c;
> >     };
> >
> > and the compiler got irritated at the use of a struct. Why would there
be a
> > problem with injecting a, b, and c into the enclosing namespace? I could
> > understand a compiler getting twitchy an an anon union within an anon
union,
> > but I didn't do that. Does this herald some future direction of the
standard
> > that I should get nervous about?
> >
> >
>
> Subclause 9.5/2 describes anonymous unions, and contains a note that
> says:  nested types and functions cannot be declared in an anonymous
> union.  Looks like you might need to declare your struct type for c
> outside the union rather than inside.  Maybe that will help.  :-)
>

The online Comeau 4.3.0.1 compiler (EDG 3.01, I think) accepts the following
without a squeak in strict mode:

int main()
{
  union {
    int a;
    float b;
    struct { char x; } c;
  };
  c.x = 'a';
}

?

hys

--
(c) 2003 Hillel Y. Sims
hsims AT factset.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: scottm@toast.net ("Scott Mayo")
Date: Thu, 9 Jan 2003 05:11:36 +0000 (UTC)
Raw View
I recently got a warning from a well known compiler which, while I'm certain
had good grounding in the standard, I don't understand.

I had an anonymous union of the form:

    union {
        int a;
        float b;
        struct { ...structurestuffing...} c;
    };

and the compiler got irritated at the use of a struct. Why would there be a
problem with injecting a, b, and c into the enclosing namespace? I could
understand a compiler getting twitchy an an anon union within an anon union,
but I didn't do that. Does this herald some future direction of the standard
that I should get nervous about?



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rmaddox@isicns.com (Randy Maddox)
Date: Thu, 9 Jan 2003 18:46:33 +0000 (UTC)
Raw View
scottm@toast.net ("Scott Mayo") wrote in message news:<3e1cd668$1@news.toast.net>...
> I recently got a warning from a well known compiler which, while I'm certain
> had good grounding in the standard, I don't understand.
>
> I had an anonymous union of the form:
>
>     union {
>         int a;
>         float b;
>         struct { ...structurestuffing...} c;
>     };
>
> and the compiler got irritated at the use of a struct. Why would there be a
> problem with injecting a, b, and c into the enclosing namespace? I could
> understand a compiler getting twitchy an an anon union within an anon union,
> but I didn't do that. Does this herald some future direction of the standard
> that I should get nervous about?
>
>

Subclause 9.5/2 describes anonymous unions, and contains a note that
says:  nested types and functions cannot be declared in an anonymous
union.  Looks like you might need to declare your struct type for c
outside the union rather than inside.  Maybe that will help.  :-)

Randy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]