# 開發工具和規格標準 [筆記] contributed by < `happyincent` > * [講座共筆](https://hackmd.io/s/HJFyt37Mx#) * [直播錄影](https://www.youtube.com/watch?v=scLFY2CRtFo) --- * C++ * 這個世紀的 C++ 為 meta language (object programming , generic programming, ...) * 改版飛快,內建許多功能,編譯器不相容問題 * gcc 和 g++ 一樣嗎? * 發現自己電腦上 (WSL, Windows Subsystem for Linux) gcc -v 和 g++ -v 的內容差不多 ``` $ diff <(gcc -v 2>&1) <(g++ -v 2>&1) 2c2 < COLLECT_GCC=gcc --- > COLLECT_GCC=g++ ``` * [ [ source ] ](https://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc) * 兩者都屬於 GNU Compiler Collection * `g++` is equivalent to `gcc -xc++ -lstdc++ -shared-libgcc` :::info gcc 是 compiler driver,參見 [編譯器和最佳化原理篇](https://hackmd.io/s/Hy72937Me) :notes: jserv ::: * musl-libc * glibc 是 LGPL (例外條款等授權問題),musl-libc 是 MIT (最寬鬆,只需留下作者名字) * 改 Alpine Linux 的 Dockerfile 時看到 musl 相關的 package * 發現 Alpine Linux 預設就是使用 musl-libc * designated initializer ``` C struct point p = { .y = yvalue, .x = xvalue }; // is equivalent to struct point p = { xvalue, yvalue }; ``` * C++ 不支援 (C++ 有 constructor) * C 更注重具體的執行順序 * 第一個 C 語言的編譯器 * 組語寫只有基本 C 功能的 C0 (the bootstrap compiler),C0 -> C1, C1 -> C2 ... * bootstraping: producing a self-compiling compiler [(wiki)](https://en.wikipedia.org/wiki/Bootstrapping_(compilers)) * e.g. PyPy * [ISO/IEC 9899](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) * null 念作 null 不是 怒偶 * `*` 念作 asterisk,`**` 念作 pointer to pointer * `&` address-of operator ``` C int a[] = { 1, 2, 3 }; if ( (void *)a == (void *)&a ) { printf("%p\n", a ); // 0x7ffff5cb1430 printf("%p\n", a + 1); // 0x7ffff5cb1434 printf("%p\n", &a + 1); // 0x7ffff5cb143c } ``` * sizeof (operator) * incomplete types (types that describe objects but lack information needed to determine their sizes) * 6.2.5 - 20 * e.g. ``` C struct A; struct A *a; sizeof(struct A); // incomplete sizeof(&a); // 8, 64-bit ``` * cdecl `declare 英文 -> C` `explain C -> 英文` * gdb * [DWARF](http://wiki.dwarfstd.org/index.php?title=DWARF_FAQ#What_is_DWARF.3F) (debugging data format, 矮人), ELF (Executable and Linkable Format, 精靈) * [gdb-peda](https://github.com/longld/peda) * Python Exploit Development Assistance for GDB * colorize * Application checkpointing * save state * e.g. crash (memory, resource, user-kernel inconsistent) * x/nfu `<address>`: Print memory [[GDB cheat sheet](https://darkdust.net/files/GDB%20Cheat%20Sheet.pdf)] * n: How many units to print (default 1) * f: Format character * a Pointer * c Read as integer, print as character * **d Integer**, signed decimal * f Floating point number * **o Integer**, print as octal * s Try to treat as C string * **t Integer**, print as binary (t = "two") * u Integer, unsigned decimal * **x Integer**, print as hexadecimal * u: Unit * b: Byte * h: Half-word (2 bytes) * w: Word (4 bytes) * g: Giant word (8 bytes) * vscode (git, debugger) * [Install on Linux](https://code.visualstudio.com/docs/setup/linux)