问题描述
是否可以告诉 C preprocessor检查功能(不是宏)是否被声明?我尝试了以下内容,但它不会出现工作
的#include<&stdio.h中GT;INT主要(无效)
{
#如果定义(printf的)
的printf(你支持printf \\ n!);
#其他
看跌期权(要么你不支持printf的,或本次测试是行不通的。);
#万一
返回0;
}
没有。 preprocessor的C编译器和C编译器处理函数声明之前运行。在preprocessor只有那里的文本处理。
然而,大多数的头文件必须包括后卫宏象 _STDIO_H _
,你可以测试在preprocessor阶段。然而,随着包括后卫宏名称不规范的解决方案是不可移植的。
Is it possible to tell the C preprocessor to check whether a function (not a macro) is declared? I tried the following, but it doesn't appear to work:
#include <stdio.h>
int main(void)
{
#if defined(printf)
printf("You support printf!\n");
#else
puts("Either you don't support printf, or this test doesn't work.");
#endif
return 0;
}
No. Preprocessor runs before the C compiler and the C compiler processes function declarations. The preprocessor is only there for text processing.
However, most header files have include guard macros like _STDIO_H_
that you can test for in the preprocessor stage. However, that solution is not portable as the include guard macro names are not standardized.
这篇关于检查是否函数是用C preprocessor声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!