or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
2018q3 Homework2 (lab0)
tags:
System-Software-2018
contributed by <
DyslexiaS
>作業說明
C Programming Lab
實驗環境
更換遠端伺服器倉庫網址
將 git repository 的 https 改為 ssh,並且設定好 ssh-key,之後 git push 就不需要輸入帳號密碼
過程
queue_t data struct
由於 q_size 和 q_insert_tail 都要求 \(O(1)\) 的時間複雜度,因此需要隨時去紀錄 tail 和 size
q_insert_head
q_insert_tail
q_free
q_remove_head
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →q_reverse
步驟
將 tail 指向 head,所以現在 tail 和 head 都是第 1 個 node
將 tmp 賦值成 head->next (也就是第 2 個 node)

開始做 while 迴圈,結束條件為 tmp == NULL,因此當節點只有 1 個時,便不會做以下步驟
將 tmp->next 存起來,才不會讓 a2 指向 a1 後,取不到 a3

將 tmp(a2) 轉向,指到 a1

將 HEAD 和 tmp 往前推進

- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →qtest 的行為和技巧
void *test_malloc(size_t size)
<harness.h>
在 harness.h 裡有這麼一段 macro:
因此我們使用 malloc 時,其實是用了 test_malloc,接著來看看 malloc 實際上會做什麼事情,以下以 doubly-linked list 來對 blocks 進行操作
節錄 test_malloc:
當我們 malloc 一個

list_ele_t
時,會被夾在 magic_header 和 find_footer 回傳的 footer 中間其中
unsigned char payload[0];
是一不佔空間的變數(Struct Hack技巧),用來存list_ele_t
的起始位置list_ele_t
邊界的紀錄點,因此在 test_free() 裡,footer != MAGICFOOTER
就會有 MSG_ERRORC99 Flexible array member:
sizeof( ) 不可使用在incomplete type的變數上
只可宣告為一個non-empty structure的最後一個成員
因此以下的宣告方式都會造成編譯錯誤:
以上 code 會有潛在的 stack smashing detected 問題
詳見
自動評分系統運作原理
GitHub