c語言用法記錄 巨集 printf s 等

2021-07-28 14:14:23 字數 1521 閱讀 5950

小數點.後「*」表示輸出位數,超出部分將被截去

printf("%.5s\n", "1234567890");   輸出  12345

printf("%.*s\n",  4, "1234567890");   輸出 1234

在棧上分配空間,函式結束後自動釋放,不用也不能呼叫 free

int* a = alloca(sizeof(int)*n);

#define colortable\

color(backgroundcolor, rgb(0,0,0), "背景顏色")\

color(titlecolor, rgb(100,0,0), "標題顏色")\

color(textcolor, rgb(0,100,0), "文字顏色")

/* 下面的** 我便定義了

stringbackgroundcolor ="backgroundcolor";

string titlecolor ="titlecolor";

string textcolor ="textcolor";

*/ #define color(key, val, desc) string key = #key;

colortable

#undef color

/* 我把顏色儲存到 map 中

m["backgroundcolor"] =rgb(0,0,0);

m["titlecolor"] =rgb(100,0,0);

m["textcolor"] =rgb(0,100,0);

*/ #define color(key, val, desc) m[key] = val;

colortable

#undef color

列印16進製制

static bool to_hexchar(const uint8_t* from, size_t n, char* to, size_t to_n)

// print_hexchar(buf, buflen, "", "");

static void print_hexchar(const uint8_t* p, uint32_t n, const char* head, const char* tail)

const char* to_hex(char* s, uint32_t u32) ;

for (i=0;i<8;i++)

s[i] = '\0';

return s;

}

安裝動態庫,如果還是提示找不到

sudo ldconfig
檢視程式動態庫

readelf -d a.out
jemalloc在linux上從安裝到使用

如果已經寫好了 malloc,  編譯的時候定義  -d jemalloc_mangle

並在根部標頭檔案中加入

#include

C語言巨集中 和 的用法

c語言巨集中 和 的用法 一 一般用法 我們使用 把巨集引數變為乙個字串,用 把兩個巨集引數貼合在一起.用法 include include using namespace std define str s s define cons a,b int a e b int main printf st...

C語言巨集裡 的用法

c 和c 中的巨集 macro 屬於編譯器預處理的範疇,屬於編譯期概念 而非執行期概念 下面對常遇到的巨集的使用問題做了簡單總結。關於 和 define warn if exp do while 0 那麼實際使用中會出現下面所示的替換過程 warn if divider 0 被替換為 do whil...

C語言 巨集中 和 的用法

巨集中 和 的用法 一 一般用法 我們使用 把巨集引數變為乙個字串,用 把兩個巨集引數貼合在一起.用法 include include using namespace std define str s s define cons a,b int a e b int main 二 當巨集引數是另乙個巨...