作者sorryChen (陈扬和)
看板Programming
标题Re: gcc #define 问题
时间Mon Oct 26 13:15:19 2009
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)
1F:→ karcher:no #endif 220.137.77.213 10/26 22:52
2F:→ sorryChen:thanks.. but that was not the problem 128.125.87.33 10/27 10:23