sysprog2018
閱讀 你所不知道的C語言: linked list 和非連續記憶體操作 共筆和觀看解說錄影。
$ git clone https://github.com/sysprog21/linux-list
$ cd linux-list
$ make
預期會得到以下輸出:
CC tests/containerof.o
LD tests/containerof
*** Validating tests/containerof ***
[ Verified ]
...
CC tests/list_cut_position.o
LD tests/list_cut_position
*** Validating tests/list\_cut\_position ***
[ Verified ]
其中 include/list.h
學習 Linux 核心原始程式碼的 linked list 資料結構實作程式碼。
#define container_of(ptr, type, member) \
__extension__({ \
const __typeof__(((type *) 0)->member) *__pmember = (ptr); \
(type *) ((char *) __pmember - offsetof(type, member)); \
})
list.h
還定義一系列操作,為什麼呢?這些有什麼益處?LIST_POISONING
這樣的設計有何意義?list_for_each_safe
和 list_for_each
的差異在哪?"safe" 在執行時期的影響為何?@
符號,這有何意義?你能否應用在後續的程式開發呢?
tests/
目錄底下的 unit test 的作用為何?就軟體工程來說的精神為何?tests/
目錄的 unit test 可如何持續精進和改善呢?qtest
得以支援