越南文翻譯

struct構造型態之位元欄位(Bit Fields)成員定義語法:
struct [struct_name]
{
struct_member_declarator
type-specifier [declarator]: constant-expression;
type-specifier [declarator]: constant-expression;
...
struct_member_declarator
}[structVars];

(unnamed field)

(padding -- 30 bits)

toaster

4 bits

light

 

要存取kitchen 佈局之成員,你可以使用kitchen.”再加上成員名,如要存取 toaster,語法就是 kitchen.toaster
接下來是設定 1 light 欄位的語法:
  kitchen.light = 1;
當你設定一個跨越位元欄位(Bit Fields)巨細的值時,就要依系統而定囉。以下是設定2toaster 欄位,因為超過數值局限,後果是以 LSB bit 0設定給 toaster 欄位:

  kitchen.toaster = 2; // LSB bit 0設定給 toaster 欄位

count

1 bit

clock

設置裝備擺設巨細

To the next int boundary

1 bit

(padding -- 31 bits)

ref: reference IBM : Declaring and Using Bit Fields in Structures

4 bits

1 bit

The size of an int (4 bytes)

flag

To the next int boundary

(padding -- 23 bits)

kitchen成員

kitchen structure 變數有8個成員,共佔16 bytes 記憶體空間。記憶體設置裝備擺設體式格局如下:

C說話的 struct 佈局型態之位元欄(Bit Fields)成員,可定義成各類分歧長度的bit位元型態翻譯例如翻譯公司需要定義16 個可以紀錄二進位的 00011011 四種數值,這時候候您就可以利用 struct 佈局型態之位元欄(Bit Fields),如此可以節約記憶體空間,且在程式可以以布林運算值直接取用,如許作也能與硬體觀念中的Flag輕鬆配合利用,讓您的程式與系統及周邊硬體間,可直接以位元運算來做暫存器存取指定喔翻譯

To the next int boundary (unnamed field)

#include
#include
struct on_off
{
  unsigned light : 1;
  unsigned toaster : 1;
  int count;/* 4 bytes */
  unsigned ac : 4;
  //--------------------
  unsigned : 4;
  unsigned clock : 1;
  unsigned : 0;
  unsigned flag : 1;
}kitchen;
int main(int argc翻譯社 char *argv[])
{
  printf( "sizeof(kitchen)=%d\r\n" , sizeof(kitchen) );
  system("PAUSE");
return 0;
}

ac

1 bit



本文出自: https://blog.xuite.net/yhchiang/blog/151121693-C%E8%AA%9E%E8%A8%80%E7%9A%84struct%E7%B5%90%E6%A7%8B%有關各國語文翻譯公證的問題歡迎諮詢華頓翻譯公司02-77260932

arrow
arrow
    文章標籤
    翻譯社
    全站熱搜

    julianr7154ln 發表在 痞客邦 留言(0) 人氣()