---
# System prepended metadata

title: Linux Kernel開發學習日誌2020.2.04
tags: [C, linux2020]

---

# Linux Kernel開發學習日誌2020.2.04

###### tags: `linux2020` `C`

## Where I am:
```shell
course week1
└── bit-wise 的應用 
    └── 課前測驗參考解答2018.q1
        └── 加解密程式 (暫時放棄)
            └── fread()    
└── 以位元駕馭能量 (先跳過)
    └── RGBAtoBW 
└── bit-field
    └── struct
```

## bit-field

參考: jserv linux-kernel 課程 week1.
[bit-field](/@sysprog/SJ8y82ZYQ?type=view)

分析以下程式碼: 

```c=1
#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;
}

```

* 自我問答
    *  line5: what is ```.a```?
        
    *  line3: one line function declaration.
    *  line7: puts vs printf?
    *  line7: one line condition syntax.

    **Answer** :
    
    * ```.a``` : designated Initializer (available since C99)
        * Ref : 
            * [Designated Initializer_第十三號艦隊](http://hungmingwu-blog.logdown.com/posts/70061-designated-initializerr-in-c99)
            * [Designated Initializer:gcc-gnu.com](http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html)

> 花一天把 C 語言規格書「瀏覽」過一次，勝過你頻頻在 Google 搜尋胡亂比對 —— 你猜對了沒有任何獎勵，只是幫 Google 賺錢罷了。「搜尋」只有在你對事物已有初步認知的時候
> 除了 C 語言，你也可以練習漢字描述，讓提問更精準
> [name=jserv老師]