问题描述
Group,
我想从另一个宏定义一个#include指令,
如果可能的话......
例如,以下内容不起作用,但基本上是我需要做的事情:
#define INCLUDE_THIS(header_name)#包括header_name
,以便当开发人员在代码中执行以下操作时
INCLUDE_THIS(" this_file.h")
头文件this_file.h包含在文件中。
任何建议???
提前致谢!
Rick
什么阻止开发人员将#include" this_file.h"
代替?我没有看到你做这件事会得到什么,即使你可以用
。
不是。您无法使用#define作为#生成预处理指令
在宏定义中是一个具有特殊含义的运算符
。
根据C99 6.10.2#4,你_can_做的是
#包括MY_INCLUDE
,其中MY_INCLUDE扩展为Header或者< Header>。
干杯
Michael
-
电子邮件:我的是/ at / gmx / dot / de address。
这不会起作用,因为宏扩展不被视为
预处理程序指令。
然而,#include的参数将是宏扩展的,如果它是b / b
与传统的...不匹配。或< ...>表格。
这可能适用于您的情况,但如果没有更多
信息,很难说。
-
int main(void){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz。\
\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\
); while(* q){i + = strchr(p,* q ++) - p; if(i> =( int)sizeof p)i- = sizeof p-1; putchar(p [i] \
);} return 0;}
Group,
I want to define a #include directive from another macro,
if possible...
For example, the following doesn''t work but is basically
what I need to do:
#define INCLUDE_THIS(header_name) #include header_name
so that when a developer does the following in the code
INCLUDE_THIS("this_file.h")
the header file "this_file.h" gets included into the file.
Any suggestions???
Thanks in advance!
Rick
What is stopping the developer from putting #include "this_file.h"
instead? I am not seeing what you would gain from doing this even if
you could.
It is not. You cannot generate preprocessing directives
using #define as "#" is an operator with special meaning
within macro definitions.
What you _can_ do, according to C99 6.10.2#4, is
#include MY_INCLUDE
where MY_INCLUDE expands to "Header" or <Header>.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
That won''t work because macro expansions are not treated as
preprocessor directives.
However, the argument to #include will be macro-expanded if it
does not match either of the conventional "..." or <...> forms.
This might work in your case, but it''s hard to tell without more
information.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
这篇关于来自#define宏的#include ???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!