考虑以下C代码:
#include <stdio.h>
#include <stdlib.h>
void fatal(const char* message){
/*
Prints a message and terminates the program.
Closes all open i/o streams before exiting.
*/
printf("%s\n", message);
fcloseall();
exit(EXIT_FAILURE);
}我使用clang2.8编译:clang -Wall -std=gnu99 -o <executable> <source.c>
和get:implicit declaration of function 'fcloseall' is invalid in C99
这是正确的,但我正在显式地编译到应该支持fcloseall()的gnu99,而不是c99。虽然代码运行,但编译时我不喜欢有未解决的警告。我怎么才能解决这个问题?
编辑:更正的tipo。
发布于 2011-01-13 12:54:51
若要在包含标准标头时包含非标准扩展,需要定义适当的特性测试宏。在这种情况下,_GNU_SOURCE应该可以工作。
#define _GNU_SOURCE
#include <stdio.h>这与-std=gnu99无关,后者支持语言扩展,而不是库扩展。
发布于 2017-01-26 18:54:34
在man的fcloseall()页面中
#define _GNU_SOURCE
#include <stdio.h>您必须定义宏-- _GNU_SOURCE是您的代码段,以及stdio.h头。_GNU_SOURCE是一个特性测试宏,用于创建可移植的应用程序。
https://stackoverflow.com/questions/4680233
复制相似问题