This is the mail archive of the gcc-help@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]

RE: problem with nameless structs and unions


>-----Original Message-----
>From: Tuukka Lehtonen [mailto:tvlehton@cc.hut.fi]
>Sent: 16 March 2001 13:49

>struct vec {
>  union {
>    int v[3];
>    struct {
>      int x,y,z;
>    };
>  };
>};

>GCC doesn't seem to support nameless structures inside unions for
>example..

  That's right.  They are disallowed by the language spec.  MS VisualC++
adds them as a custom extension.

>This would be very useful in many situations.
>Is there any way to go round this flaw, to achieve the same functionality
>as the above structure should provide, that is accessing the same elements
>eith either indexing them or using plain vector component names?

  You could always add tags and then use #defines for shortcuts

struct vec {
  union {
    int v[3];
    struct {
      int x,y,z;
    } innerstruct;
  } innerunion;
};

#define x innerunion.innerstruct.x
#define y innerunion.innerstruct.y
#define z innerunion.innerstruct.z

but of course that's a bit risky when the names are as simple as 'x'. 

  I read recently that the cygwin version of Gcc has been extended to
deal with these structures since they're used in the Windows system
headers.  You might want to look into that possibility: check out
Message-ID: <Xns9065B4B6BD2FFmarcotechnobore@technoboredom.net> 
(news:<Xns9065B4B6BD2FFmarcotechnobore@technoboredom.net>)


      DaveK
-- 
 All your base are belong to us!


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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