contributed by < happyincent >
-std=gnu11
、嘗試 Implicit Rules、加上 dependency.PHONY
CFLAGS
[source]
-O0
: 關閉優化,default optimization level-g
: Options for Debugging-Wall
: 啟用容易被避免的 warnings-Werror
: Make all warnings into errors.-std=gnu11
-std=c11
會無法編譯
console.h
: unknown type name ‘fd_set’
fd_set
定義在 <sys/select.h> 屬於 C POSIX library 而非 ISO Charness.c
: implicit declaration of function ‘random’ (‘sigsetjmp’)
$(GIT_HOOKS)
scripts/install-git-hooks
時會 touch 檔案: .git/hooks/applied
$(GIT_HOOKS)
檔案已存在且這個 target 沒有 prerequisites 需要確認,因此 Make 會認為已經 up to date 便不會再執行
@
: 不 echo 該行指令 (Recipe Echoing):=
: Simply expanded variables, =
: recursively expanded variables,?=
: conditional variable assignment [source]
all
queue.o, qtest
-c
: compile or assemble the source files, but do not link-o file
: output in file filedep
[source]
-M
: output a rule suitable for make describing the dependencies of the main source file-MM
: 找出非 include 系統且非間接 include 的 source file dependencies
test
clean
.dSYM
: debug symbols*~
: 編輯器備份檔Queue Structure
size_t q_size
來達成在 O(1) 時間內得到 queue elements 的數目
sizeof(long) = sizeof(size_t)
[stackoverflow: size_t ]list_ele_t *tail
紀錄 queue 中 tail element 的位址q_insert_head
static inline list_ele_t *ele_new(char *s)
,但發現會造成更多的 jmp (BL, BNE, …) 次數
-O0
(optimization level 0) 時可能不會展開 inline [source] [gcc-inline]
__attribute__((always_inline))
強制做 inlineq_reverse
-O0
(下圖左)、-O1
(下圖右) compile queue.c,並比較 IDA Pro disassemble 後 q_insert_head
的 graph 圖O0
最多需 8 次 jmpO1
最多需 6 次 jmpO0
最多需 6 次 jmpO1
最多需 3 次 jmp-O0
ERROR: Time limit exceeded
-O0, -O1, -O2, -O3
測試 10 次並計算平均分數 (timeout 10 秒 total = 0)