di**********@yahoo.com writes:
Hi.I have come across this structure which I could not understand.Could
anybody please explain this?
struct
{
int:a;
int:b;
char c;
double d;
}asd;
now what is int:a? Is it some way related with bits? the size of the
structure is 12 in linux systems.Thanks for help.
Are you *sure* that's what it says?
As Eric Sosman pointed out, "int:a;" is legal only if a is a constant
integer expression; it's then an anonymous bit field; a is the width
of the bit field, not its name. Most likely it would have to be a
macro, but macro names are traditionally written in all-caps. This
would have to be equivalent to:
struct {
int :8;
int :16;
char c;
double d;
} asd;
(Incidentally, this creates an anonymous struct type and a single
object of that type, which is rarely going to be useful.)
If the actual declaration is something like this:
struct {
int a:8;
int b:16;
char c;
double d;
} asd;
then a and b are *named* bit fields. (Beware: plain int bit fields
can be either signed or unsigned. You usually want bit fields to be
unsigned; if so, replace 'int" with "unsigned int".)
If you're asking about code you don't understand, you can very easily
lose vital details if you try to paraphrase it. That's why we
encourage people to copy-and-paste the *exact* actual code, so we
don't have to guess.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.