Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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 3:58am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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).
Sergey Alexandrovich Kryukov at 25-Dec-12 16:00pm

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

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 174
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911

Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 25 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100