anonymous struct members

R

richardw

hi!

this struct seems to be vaild c99:

struct foo {
int:1;
};


when makes such a struct sense?
is the anonymous member used for padding?

thanks,
//richard
 
B

Ben Bacarisse

richardw said:
this struct seems to be vaild c99:

struct foo {
int:1;
};

From 6.7.2.1 Structure and union specifiers

7 The presence of a struct-declaration-list in a struct-or-union-
specifier declares a new type, within a translation unit. The
struct-declaration-list is a sequence of declarations for the
members of the structure or union. If the struct-declaration-
list contains no named members, the behavior is undefined.

so "valid" is a debatable description! Paragraph 7 is not a constraint
so no diagnostic is required, but gcc gives one when invoked in
conforming mode.
when makes such a struct sense?
is the anonymous member used for padding?

I don't think it does make sense, except perhaps as a compiler test
case.
 
B

Ben Bacarisse

China Blue Police Box said:
Yes, padding.

I see you interpreted the question slightly differently. I thought the
question was about the whole struct (and that's undefined,
i.e. "invalid").

Just to be clear, the passage I quoted relates to the whole struct;
unnamed bit-fields are permitted provided there are some named members
in the struct.

<snip>
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top