Unnamed union

F

Frank Roland

I know it is possible to use unnamed struct or unions inside of struct like
in the following example:

typedef struct {
union {
int moin;
char carl;
};
int bon;
} dastruct;

int main(int argc, char * argv[])
{
dastruct thestruct;

thestruct.carl = 'a';
thestruct.bon=6;
...


Now I have a compiler which does not allow me to acces moin or carl unless I
give the union a name, like here:

typedef struct {
union {
int moin;
char carl;
} x;
int bon;
} dastruct;


int main(int argc, char * argv[])
{
dastruct thestruct;

thestruct.x.carl = 'a';
thestruct.bon=6;
....


What I wonder is, wheter unnamed struct and unions are a feature of newer C
standard (C99)?

Kind regards,
Frank
 
E

Eric Sosman

Frank said:
I know it is possible to use unnamed struct or unions inside of struct like
in the following example:

typedef struct {
union {
int moin;
char carl;
};
int bon;
} dastruct;

I know that the Earth is flat, that the Moon is made of
green cheese, and that the stuff advertised in all those
E-mails really will make my member grow larger.
What I wonder is, wheter unnamed struct and unions are a feature of newer C
standard (C99)?

No, and this is not a change: No C Standard has permitted
nameless elements in structs, with the exception of a special
case involving bit-fields. Various compilers have supported
this as an extension to the C language, but it has always
been an extension.
 
T

Tristan Miller

Greetings.

What I wonder is, wheter unnamed struct and unions are a feature of newer
C standard (C99)?

I asked this back in message <[email protected]> -- the answer
is no, C99 does not support anonymous unions. Pity, as they are supported
in C++, and I actually use them from time to time.

Regards,
Tristan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top