是否可以告诉预处理器检查函数(而不是宏)是否被声明?我尝试了以下方法,但看起来并不奏效:检查函数是否用C预处理器声明?
#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;
}
我对此很感兴趣。您正在使用的库应该是一致的,以获得您的示例:不会有没有printf的stdio.h,并且如果printf可能在遥远的将来被删除,您现在不会知道替换是如何进行的被称为。 – flokra 2009-11-17 14:30:31
我在想这不是专门针对printf的,只是任何函数名称。但是,如果你想知道函数是否存在,只需调用它 - 编译器错误会告诉你:-) – paxdiablo 2009-11-17 14:39:52
我的主要动机是检查函数如bcopy()或arc4random()(编写跨平台程序时) ,这些并不总是被定义的。 – Michael 2009-11-17 14:59:39