linux2020
C
Q&A
各位晚安,我在學習week 1 bit field的時候,
因為看不懂structure 中 designated initializer 的用法
於是嘗試查詢C 語言規格書,
並把查詢的過程記錄在HackMD中,
想請問各位同學,
在遇到沒看過的語法時,
你們都是怎麼下關鍵字搜尋的呢?
有什麼訣竅能讓自己的關鍵字下得更精準呢?
有鑒於課程中有許多地方需要查詢第一手資料,也就是規格書
我列出了自己查詢的思路,以及各種嘗試的心得跟大家分享。
首先,根據
你所不知道的 C 語言: 開發工具和規格標準
內,
所以我嘗試著相同的方法,在遇到問題時,
course week1
└── bit-field
#include <stdbool.h>
#include <stdio.h>
bool is_one(int i) { return i == 1; } // a function input
int main() {
struct { signed int a : 1; } obj = { .a = 1 }; // struct.
// obj is a structure variable.
puts(is_one(obj.a) ? "one" : "not one"); // puts vs printf?
return 0;
}
line 5: .a
的用法看不懂.
分析.a
中的 .
是什麼
根據過往經驗,英文中.
通常唸作 "Dot".
打開 C語言規格書,使用關鍵字 Dot
搜尋
第一個結果出現 Dot operator(structure), 在 chapter 6.5.2.3
我的看法:
查詢 Chapter-6.5.2.3 可能會有結果
使用關鍵字 6.5.2.3
搜尋
6.5.2.3 Structure and union members
.
operator and an identifier designates (指定) a member of a structure or union object.綜合第五行
struct { signed int a : 1; } obj = { .a = 1 };
–> 推測可能與 designate a member of a structure 有關
搜尋 designate
designated initializer, 6.7.8