This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Anonymous structs in C++




   Hi,


   I'm working on Winelib, the library that allows to recompile C/C++
windows programs on Linux. Of course on Windows these programs often
have anonymous structs/unions. There's been progress for supporting
these in gcc 2.95.2 but it still wasn't complete. So I decided to test
the latest gcc from CVS and I've been impressed.
   Anonymous unions and structs work in both C and C++. Congratulations
guys.

   Actually there's still a small bug in the anonymous struct support in
g++. I thought I'd mention it here in case it went by unnoticed (didn't 
see it in the archives). With the program below g++ says:

$ g++ -c foo.cpp
foo.cpp: In function `int main()':
foo.cpp:28: `struct anon_struct2' has no member named `a'
foo.cpp:29: `struct anon_struct2' has no member named `b'

   This works well in C. Here's the program:
struct nested {
    int a;
    int b;
};

struct anon_struct1 {
  struct {
    int a;
    int b;
  };
  int c;
};

struct anon_struct2 {
  struct nested;
  int c;
};

int main()
{
  struct anon_struct1 v1;
  struct anon_struct2 v2;

  v1.a=1;
  v1.b=2;
  v1.c=3;

  v2.a=1;
  v2.b=2;
  v2.c=3;

  return 0;
}



--
Francois Gouget         fgouget@free.fr        http://fgouget.free.fr/
                     Linux: the choice of a GNU generation


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]