Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

structures in C 1

Status
Not open for further replies.

shilpashetty27

Technical User
Apr 12, 2007
32
CA
Hi all,

Can anyone please enlighten me on what the following initialization means. I have not come across this kind of declaration thus far and not sure what it does or means.


struct
{
int event :3; //not sure what this initialization means
bool flag :1;
};

Thanks in advance!
Shilpa
 
int event : 3; means that 'event' is 3 bits in an int.

If you need to conserve space you can do so:

struct
{
int End_Of_Line : 1;
int Start_Of_Line : 1;
int Something_Inserted : 1;
...
} Flag;
then you can access those in the usual manner 'Flag.End_Of_Line' and so forth.

I have used it on a date format where i had a limited number of bytes in a logging microprocessor:
typedef struct
{
word Year : 12; /* 0 - 4095 */
word Month : 4;
word Date : 5;
word Hour : 5;
word Minute : 6;
byte Second : 6;
} T_TIMEGROUP; /* 6 bytes */

Totte
Keep making it perfect and it will end up broken.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top