By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Function of ":" in a structure

P: n/a
What is the function of ":" and followed number (2 or 1) in the followin
structure?

typedef struct {
unsigned int A : 2;
unsigned int B : 2;
unsigned int C : 2;
unsigned int D : 2;
unsigned int E : 1;
} ASampleStruct;
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

<hu-axiang> wrote in message
news:42***********************@news.optusnet.com.a u...
What is the function of ":" and followed number (2 or 1) in the followin
structure?

typedef struct {
unsigned int A : 2;
unsigned int B : 2;
unsigned int C : 2;
unsigned int D : 2;
unsigned int E : 1;
} ASampleStruct;


Those are "bit fields". They specify how many bits of the struct are
actually allocated for each of the members. They're useful sometimes when
you need a specific number of bits for your data. Read up about how to use
them in your favorite book.

By the way, you're using C-style notation for your struct definition, which
is kind of overkill. C+ structs are defined more simply, like this:

struct ASampleStruct
{
// add members here
};

-Howard
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Browse more C / C++ Questions on Bytes