2011-01-16 15 views

答えて

16

これはbitfieldです。

ビットフィールドがintに埋め込まれているので、この特定のビットフィールドはあまり意味をなさないが、16ビットタイプを使用するとスペースが無駄になります。

通常、あなたはビットサイズの要素を含む構造体のためにそれを使用している:それはビットフィールドです

struct { 
    unsigned nibble1 : 4; 
    unsigned nibble2 : 4; 
} 
10
struct name { int a:16; } 

a16ビットメモリ空間として定義されることを意味します。

struct name { int a:16; int b:16; } 

intは、32ビット(4バイト)であれば、その後1 intのメモリを分割する:intから残りのビット(16ビット)このように、b言う、定義された別の変数を使用することができます2つの変数abに変換します。

PS:私は、sizeof(int) = 4バイト、1バイト= 8ビットを想定してい

2
struct s 
    { 
    int a:1; 
    int b:2; 
    int c:7; 
    };/*size of structure s is 4 bytes and not 4*3=12 bytes since all share the same space provided by int declaration for the first variable.*/ 
struct s1 
    { 
    char a:1; 
    };/*size of struct s1 is 1byte had it been having any more char _var:_val it would have been the same.*/ 
関連する問題