Jump to content
Ian Harris

Anonymous Structs Not Allowed In Union

Recommended Posts

typedef union _CTRL_TRF_SETUP
{
struct
{
	uns8 _byte[8];
};

struct
{
	uns8 bmRequestType;
	uns8 bRequest;	
	uns16 wValue;
	uns16 wIndex;
	uns16 wLength;
};

} CTRL_TRF_SETUP;

[/code]

 

Using 6.87, it isn't possible to compile the above code (which works fine in other compilers). You need to name each struct:

 

typedef union _CTRL_TRF_SETUP
{
struct
{
	uns8 _byte[8];
} y;

struct
{
	uns8 bmRequestType;
	uns8 bRequest;	
	uns16 wValue;
	uns16 wIndex;
	uns16 wLength;
} x;

} CTRL_TRF_SETUP;

 

This compiles - and you can use it with the names, but it's pretty clumsy. It would be nice just to be able to use the struct members without having to specify the struct they come from.

 

regards

Ian.

Share this post


Link to post
Share on other sites

If you have the same variable name in both structures (could happen if structures where similar in content) then you would have to name the structure you need anyway.

 

Anonymous structures are not ANSI C are they ? but a Microsoft C extention. May not be allowed in C++.

 

My thrupence worth.

 

Reynard.

Share this post


Link to post
Share on other sites
If you have the same variable name in both structures (could happen if structures where similar in content) then you would have to name the structure you need anyway.

 

Anonymous structures are not ANSI C are they ? but a Microsoft C extention. May not be allowed in C++.

 

My thrupence worth.

 

Reynard.

 

I understand they were introduced in C99. Still, it's a nice feature, given that BoostC also supports things like templates that aren't standard it would be nice to support this as well.

 

cheers

Ian.

Share this post


Link to post
Share on other sites

Sure a nice feature. I still prefer to use the full variable name for clarity to which variable I am using. Sometime sizeof(struct) is nice to use. It all depends on your code and preference I suppose.

 

You will be wanting anonymous unions inside structs next ;)

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...