考虑以下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);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用clang 2.8编译: clang -Wall -std=gnu99 -o <executable> <source.c>
得到: implicit declaration of function 'fcloseall' is invalid in C99
这是真的,但我明确地编译为gnu99 [应该支持fcloseall()],而不是c99.虽然代码运行,但我不喜欢在编译时有未解决的警告.我怎么解决这个问题?
编辑:更正了tipo.
要在包含标准标头时包含非标准扩展,您需要定义适当的功能测试宏。在这种情况下_GNU_SOURCE应该有效。
#define _GNU_SOURCE
#include <stdio.h>
Run Code Online (Sandbox Code Playgroud)
-std=gnu99这与启用语言扩展无关,与库扩展无关。