sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Frederiek's Avatar

What does this (unusual?) structure definition mean?


Question posted by: Frederiek (Guest) on July 11th, 2006 04:15 PM
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

3 Answers Posted
Jewel's Avatar
Guest - n/a Posts
#2: Re: What does this (unusual?) structure definition mean?


Frederiek wrote:
Quote:
Originally Posted by
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.

BigBrian's Avatar
Guest - n/a Posts
#3: Re: What does this (unusual?) structure definition mean?


Frederiek wrote:
Quote:
Originally Posted by
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

Jakob Bieling's Avatar
Jakob Bieling July 11th, 2006 04:45 PM
Guest - n/a Posts
#4: Re: What does this (unusual?) structure definition mean?

Frederiek <fd_news@hotmail.comwrote:
Quote:
Originally Posted by
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
--
jb

(reply address in rot13, unscramble first)


 
Not the answer you were looking for? Post your question . . .
196,987 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,987 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors