Click here to Skip to main content
Sign Up to vote bad
good
See more: C++
struct S2{//32
    long a1:2;
    long a2:30;
    LONG64 a;
};
long a1:2; the colon after the long is mean what?
Posted 25-Dec-12 2:58am


1 solution

This is a bit field (You can use Google for more information and samples).
 
Essentially, it means that 2 bits are used for a1 and 30 bits for a2. 64 bits are used for a. This give a total of 96 usable bits. Actual size might be bigger for alignment purpose.
 
Fot the bit fields themselves, they will generally be combined up to the size of an int and if more bits are required, the will start on next boundary. Also, the maximum number of will usually be 32 or 64 depending on the platform.
 
Thus a bit field can essentially be used to split a type into multiple bit fields. Thus is can be used to reduce memory usage in some case or also simply to define a structure that matches somne hardware registers (more common in Embedded software).
  Permalink  
Comments
Sergey Alexandrovich Kryukov - 25-Dec-12 16:00pm
5. —SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 545
1 Ron Beyer 316
2 Tadit Dash 233
3 samadhan_kshirsagar 229
4 OriginalGriff 198
0 Sergey Alexandrovich Kryukov 7,061
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,370
4 CPallini 3,034


Advertise | Privacy | Mobile
Web03 | 2.6.130619.1 | Last Updated 25 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid