简体   繁体   中英

getting “implicit declaration of function 'fcloseall' is invalid in C99” when compiling to gnu99

Consider the following C code:

#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);
}

I'm using clang 2.8 to compile: clang -Wall -std=gnu99 -o <executable> <source.c>

And get: implicit declaration of function 'fcloseall' is invalid in C99

Which is true, but i'm explicitly compiling to gnu99 [which should support fcloseall()], and not to c99. Although the code runs, I don't like to have unresolved warnings when compiling. How can i solve this?

Edit : corrected tipo.

To include non-standard extensions when you include standard headers you need to define the appropriate feature test macro. In this case _GNU_SOURCE should work.

#define _GNU_SOURCE
#include <stdio.h>

This is independent of -std=gnu99 which enables language extensions, not library extensions.

Here in the man page of fcloseall()

#define _GNU_SOURCE 
#include <stdio.h>

You have to define macros _GNU_SOURCE is you snippet, along with stdio.h header. _GNU_SOURCE is a feature test macros which is used to create portable application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM