验证问题 [英] validating problem
问题描述
大家好,
我有一个问题,我必须执行
a部分代码只有当一个头文件是
时在源文件中的某个地方。可以一些
身体解释如何做。
例如
如果包括placebo.h {
执行这部分代码
}
谢谢
Divya
Hi all,
I have got a problem where i have to execute
a portion of code only when a header file is
included somewhere in the source file. Can some
body explain how to do it.
for example
if included placebo.h{
execute this part of code
}
Thanks
Divya
推荐答案
foodic写道:
大家好,
我有一个问题,我必须执行
一部分代码只有当头文件是
包含在源文件中的某个位置。一些
身体可以解释如何做到这一点。
例如
如果包括placebo.h {
执行这部分代码
}
谢谢
Divya
Hi all,
I have got a problem where i have to execute
a portion of code only when a header file is
included somewhere in the source file. Can some
body explain how to do it.
for example
if included placebo.h{
execute this part of code
}
Thanks
Divya
你可以这样做:
文件placebo.h:
#define PLACEBO_H
.....
文件无论如何。
....
#ifdef PLACEBO_H
代码执行
#endif
....
请注意,只有在包含头文件_before_
此构造时,这才有效。这应该不是什么大问题,因为你所有的包含
应该在文件的最开头......
You could make this:
File placebo.h:
#define PLACEBO_H
.....
File whatever.c
....
#ifdef PLACEBO_H
code to execute
#endif
....
Note that this will only work if the header file is included _before_
this construct. This should be no great problem since all your includes
should be at the very start of the file...
foodic写道:
foodic wrote:
大家好,
我有一个问题,我必须执行
一部分代码只有当头文件是
包含在源文件中的某个位置。一些
身体可以解释如何做到这一点。
例如
如果包括placebo.h {
执行这部分代码
}
谢谢
Divya
Hi all,
I have got a problem where i have to execute
a portion of code only when a header file is
included somewhere in the source file. Can some
body explain how to do it.
for example
if included placebo.h{
execute this part of code
}
Thanks
Divya
不,你不能直接这样做。但是,大多数头文件定义了一个
宏来识别例如:
#ifndef _BACKWARD_ALLOC_H
#define _BACKWARD_ALLOC_H 1
其他人都是这样的。
所以你可以使用:
#ifdef _HEAD_FILE_NAME_H
/ *做点什么* /
#endif
>
Cong Wang在29/07/05写道:
Cong Wang wrote on 29/07/05 :
不,你不能直接这样做。但是,大多数头文件都定义了
宏来识别自己。例如:
#ifndef _BACKWARD_ALLOC_H
No,you can''t do this directly.However,most of the head files define a
macro to identify itself.For example:
#ifndef _BACKWARD_ALLOC_H
请记住,以_ [_ A-Z]开头的标识符属于
实施名称空间。
#ifndef H_BACKWARD_ALLOC
对用户来说很好。
-
Emmanuel
C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
C库: http://www.dinkumware。 com / refxc.html
" Mal nommer les choses c''est ajouter du malheur au
monde。 - Albert Camus。
Please keep in mind that identifiers beginning with _[_A-Z] belong to
the implementation name space.
#ifndef H_BACKWARD_ALLOC
is fine for a user.
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html
"Mal nommer les choses c''est ajouter du malheur au
monde." -- Albert Camus.
这篇关于验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!