Click here to Skip to main content
13,593,048 members
Rate this:
Please Sign up or sign in to vote.
See more:
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

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 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
Top Experts
Last 24hrsThis month

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

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