public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: llewelly@xmission.com
To: Mathieu Fluhr <mfluhr@nero.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Anonymous union members problem
Date: Mon, 19 Apr 2004 14:53:00 -0000	[thread overview]
Message-ID: <s3rhdvgdno3.fsf@xmission.xmission.com> (raw)
In-Reply-To: <1082380113.10142.9.camel@c-l-175>

Mathieu Fluhr <mfluhr@nero.com> writes:

> Hello
> 
> I am porting VC++ source code to Linux using g++ 3.3 and I am currently
> getting some errors with C++ code like this sample program:
> 
> 
> struct foo
> {
>   struct

Anonymous structs are never described in the ISO C++
    standard. Therefor they are an extension or an error. GCC supports
    anonymous structs with -fms-extensions. 

>   {
>     typedef int structType;

However, gcc does not support typedefs within anonymous structs, even
    with -fms-extensions. I don't know why. (Probabably because
    standard C++ does not allow typedefs within anonymous unions.) If
    MS supports typedefs within anonymous unions, you might consider
    submiting a feature request.

Better, email MS and ask them to stop encouraging people to use
    extensions. :-)

>     union
>     { 
>       int test;
>     };
>   };
> };
> 
> int main()
> {
>   return 0;
> }
> 
> When I try to compile this program, I get the following message:
> 
> mathieu@c-l-175:~/tests/bitfields$ g++-3.3 -Wall bitfields.cpp
> bitfields.cpp:5: error: `typedef int foo::<anonymous
> struct>::structType'
>    invalid; an anonymous union can only have non-static data members
> 
> Is this invalid C++ code ?

Yes. Anonymous structs are mentioned nowhere in the
    standard. (Structs, and classes in general are covered in 
    ch 9. Anonymous unions are in 9.5/2 .)

> If yes is there a way to make it valid

struct foo
{
    typedef int structType;
    union { int test; };
};

> and
> compilable under Linux ?

struct foo
{
    typedef int structType;
    //Need -fms-extensions for anonymous struct.
    struct { union { int test; }; };
};

Now I have a question for you: What is an anonymous struct good for? 
    

      parent reply	other threads:[~2004-04-19 14:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-19 13:09 Mathieu Fluhr
2004-04-19 13:15 ` Eljay Love-Jensen
2004-04-19 13:55   ` Mathieu Fluhr
2004-04-19 14:28     ` Eljay Love-Jensen
2004-04-19 14:59     ` llewelly
2004-04-19 14:53 ` llewelly [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s3rhdvgdno3.fsf@xmission.xmission.com \
    --to=llewelly@xmission.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=mfluhr@nero.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).