--- title: Linux kernel memo (week 1) tags: Linux description: Just simple memo for week1 about C pointer and link list in Linux Kernel --- # Linux kernel memo (week 1) <!-- Put the link to this slide here so people can follow --> http://wiki.csie.ncku.edu.tw/linux/schedule --- # Engineering 軟體缺失導致的危害 1970 年代推出的首款廣體民航客機波音 747 軟體由大約 40 萬行程式碼構成,而 2011 年引進的波音 787 的軟體規模則是波音 747 的 16 倍,約 650 萬行程式碼。換言之,你我的性命緊繫於一系列極為複雜的軟體系統之中,能不花點時間了解嗎? 軟體開發的安全性設計和測試驗證應獲得更高的重視 解讀計算機編碼 人們對數學的加減運算可輕易在腦中辨識符號並理解其結果,但電腦做任何事都受限於實體資料儲存及操作方式,換言之,電腦硬體實際只認得 0 和 1,卻不知道符號 + 和 - 在數學及應用場域的意義,於是工程人員引入「補數」以表達人們認知上的正負數 您有沒有想過,為何「二補數」(2’s complement) 被電腦廣泛採用呢?背後的設計考量是什麼?本文嘗試從數學觀點去解讀編碼背後的原理 [How branches influence the performance of your code and what can you do about it?](https://johnysswlab.com/how-branches-influence-the-performance-of-your-code-and-what-can-you-do-about-it/) From [Linux 核心設計/實作 (Linux Kernel Internals) ](http://wiki.csie.ncku.edu.tw/linux/schedule) --- # Pointer in C https://hackmd.io/@sysprog/c-pointer https://hackmd.io/@sysprog/c-linked-list ---- ## Complicated pointer ``` (*(void(*)())0)(); equal to typedef void (*funcptr)(); (* (funcptr) 0)(); ``` We can use [godbolt](https://gcc.godbolt.org/) to check it. Ref From “Understanding Declarations” in [C Traps and Pitfall](http://www.literateprogramming.com/ctraps.pdf) and [你所不知道的C語言:指標篇](https://hackmd.io/@sysprog/c-pointer) ---- ## How to read it ![](https://i.imgur.com/5EKbZ8h.png) http://c-faq.com/decl/spiral.anderson.html ---- ## Practice ``` void **(*d) (int &, char **(*)(char *, char **)); ``` --- # Pointers vs. Arrays https://hackmd.io/@sysprog/c-pointer#Pointers-vs-Arrays --- # Function Pointer https://hackmd.io/@sysprog/c-pointer#Function-Pointer --- # Pointer to a pointer https://hackmd.io/@sysprog/c-pointer#%E6%B2%92%E6%9C%89%E3%80%8C%E9%9B%99%E6%8C%87%E6%A8%99%E3%80%8D%E5%8F%AA%E6%9C%89%E3%80%8C%E6%8C%87%E6%A8%99%E7%9A%84%E6%8C%87%E6%A8%99%E3%80%8D --- # Linked-List https://hackmd.io/@sysprog/c-linked-list#%E5%BE%9E-Linux-%E6%A0%B8%E5%BF%83%E7%9A%84%E8%97%9D%E8%A1%93%E8%AB%87%E8%B5%B7 ---- ## Linked list in linux kernel https://hackmd.io/@sysprog/c-linked-list#Linked-list-%E5%9C%A8-Linux-%E6%A0%B8%E5%BF%83%E5%8E%9F%E5%A7%8B%E7%A8%8B%E5%BC%8F%E7%A2%BC https://github.com/torvalds/linux/blob/master/include/linux/list.h ---- ## Container of ![](https://i.imgur.com/n4ws09J.png) https://hackmd.io/@sysprog/c-linked-list#container_of --- # :100: :muscle: :tada: --- ### Wrap up ![](https://truth.bahamut.com.tw/s01/201911/4e3eb1c83a9c6204fd1cdcff2206e831.JPG) --- ### Thank you! :sheep: