What does this (unusual?) structure definition mean?

F

Frederiek

Hi,

What exactly does the following code mean? More specific, what are the
colons for? Is this some kind of way to initialize the structure
members?

struct somestruct
{
unsigned char a:1;
unsigned char b:1;
unsigned char c:1;
};

Regards,

Frederiek
 
J

Jewel

Frederiek said:
Hi,

What exactly does the following code mean? More specific, what are the
colons for? Is this some kind of way to initialize the structure
members?

struct somestruct
{
unsigned char a:1;
unsigned char b:1;
unsigned char c:1;
};

Regards,

Frederiek

Look in your favorite reference for bitfields.
 
B

BigBrian

Frederiek said:
Hi,

What exactly does the following code mean? More specific, what are the
colons for? Is this some kind of way to initialize the structure
members?

struct somestruct
{
unsigned char a:1;
unsigned char b:1;
unsigned char c:1;
};

Regards,

Frederiek

It's declaring a bit field.

-Brian
 
J

Jakob Bieling

Frederiek said:
What exactly does the following code mean? More specific, what are the
colons for? Is this some kind of way to initialize the structure
members?

struct somestruct
{
unsigned char a:1;
unsigned char b:1;
unsigned char c:1;
};

It's called a bit-field. a, b and c are each one bit (that is what
the number after the colon means).

regards
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top