# 2019q3: 回顧 Homework [_1_](https://hackmd.io/@sysprog/HJvjIvDIr) / [_2_](https://hackmd.io/@sysprog/BkZ4h5xPB) ![](https://i.imgur.com/SRkbFUf.jpg) > 《返校》台詞:「你是忘記了,還是害怕想起來?」 --- - [ ] colinyoyo26 * 檢討事項 : 擴充到負數以及化簡 * 補充資訊 : `^` 讓 `x == 0` 變 normal case ```cpp #include <stdbool.h> bool func(int x) { return ((x & -x) == x) ^ ((x & -x) == -x ); } ``` --- - [ ] kksweet8845 * 檢討事項 : * 數值處理 : 推論方式有錯誤 * 補充資訊 : --- - [ ] uccuser159 * 檢討事項 : * C99為什麼需要 function designator,考量點為何? * 解釋Driver & q_reverse表達的修正 * 補充資訊 : - [ ]function designator考量點 考慮以下程式: ```cpp #include <stdio.h> int (*fptr1)(int); int test1(int a){ a = a + 1; return a; } int main() { fptr1 = test1; printf("test1:%x, fptr1:%x, *fptr1=%x\n", test1, fptr1, *fptr1); printf("&test1: %x, &fptr1: %x\n", &test1, &fptr1); return 0; } /* test1:400593, fptr1:400593, *fptr1=400593 &test1: 400593, &fptr1: 601048 */ ``` test1 是一個 `int` type 的函式 : int (int) fptr1 是一個 pointer to function with returning type : int(*)(int) *fptr1 因為 function pointer(fptr1) 搭配 * 運算子的運算視為 function designator ,且 fptr1 有 returning type,所以轉變成pointer to function returning type : int (int) **若沒有 function designator** ,在 *fptr1 時會抓到錯誤的程式段。 以上面的例子來說,會抓到 empty function。 Reference -[Why we need function designator](https://hackmd.io/@justapig9020/wwn-func_des?fbclid=IwAR1sZ9nVoFEPDyqih7xWrhBl6bOiAzxVyENoKB8aRUoTYRjTWnxgChuXZ3I) - [ ] Driver [Driver](https://en.wikipedia.org/wiki/Driver_(software))定義 : > A driver in software provides a **programming interface** to **control** and **manage** **specific lower level interface** that is often linked to a specific type of hardware, or **other low-level service**. 在 Readme 中提到: scripts/driver.py : The C lab driver program, runs qtest on a standard set of traces Driver 扮演是一個操作 qtest 執行一連串的 task (例如:q_insert_head . q_free ...等等)的角色。 - [ ] q_reverse ```cpp void q_reverse(queue_t *q) { if (q == NULL || q->size == 0 || q->size == 1) return; list_ele_t *cur = q->head->next; q->head->next = NULL; list_ele_t *temp; q->tail = q->head; while (cur != NULL) { temp = cur->next; cur->next = q->head; q->head = cur; cur = temp; } ``` 想法是原本 queue 的指向關係為 A → B → C → D → E → NULL reverse 即是將關係反過來:原本 A->next = B 改成 B->next = A 最一開始先將 cur 指向 B , q->head->next 指向 NULL (即 A ->next = NULL),再將 q->tail 換成 q->head (q->tail 指向 A) 再來就是換個別 node 的 next 關係 ![](https://i.imgur.com/FKowZgB.png) STEP1. 儲存 cur->next 先儲存起來 STEP2. 先讓 cur 指向我們所想對調的 next 關係 (cur 指向 B , B->next 要指向 A) STEP3. 再將 q->head 更新為 cur (B → A → NULL) STEP4. 最後更新 cur 為下一個要對調 next 關係的 node ---