Re: gcc #define 問題

看板Programming作者 (陳揚和)時間16年前 (2009/10/26 13:15), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串3/3 (看更多)
Thank you very much for the reply. Yes, I can type multiple line with #define #endif everytime, but I tried to shrink multiple lines in to one line. For example: #ifndef _OPENMP #define __OPENMP_FOR_PARALLEL__(openmp_flag) \ LOG_INFO("Info %d: Use 1 CPU.\n", CONFIG_LOG);} #else #define __OPENMP_FOR_PARALLEL__(openmp_flag) {\ int numberOfCPUs = omp_get_num_procs();\ std::cout << "Use " << numberOfCPUs << " CPUs.\n";\ openmp_flag omp parallel for\ } It doesn't work because the '#' sign. (Excuse me that I suddently can't type chinese). ※ 引述《LPH66 ((short)(-15074))》之銘言: : ※ 引述《sorryChen (陳揚和)》之銘言: : : GCC preprocessor 中 : : '#'符號有特別的意義 是將參數變成字串 : : ex: #define STRINGLIZE(ivalue) #ivalue : : STRINGLIZE(1)會是 "1" : : '##'也有特別的意義 是將兩個參數接在一起 : : 我的問題是, 如何escape '#'這個符號呢? : : ex: : : #define __MYFLAG__ '#pragma OMP for' : : preprocessor 會把#當成特殊符號 要怎麼escape呢 : : 我試過 #define __MYFLACG(a) a : : 然後再用 #pragma 填到a中 好像不行...不知道有沒有高手知道正卻的作法 : 這樣的話倒不如使用類似這樣的寫法 : #ifdef USEOMP : #pragma OMP for : #endif : 然後編譯時用 -D 定義符號即可打開... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 128.125.87.33 ※ 編輯: sorryChen 來自: 128.125.87.33 (10/26 13:16)

10/26 22:52, , 1F
no #endif
10/26 22:52, 1F

10/27 10:23, , 2F
thanks.. but that was not the problem
10/27 10:23, 2F
文章代碼(AID): #1AvJ1ghj (Programming)
文章代碼(AID): #1AvJ1ghj (Programming)