...">

Getting "implicit function declaration" fcloseall "is not valid in C99" when compiling in 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 use clang 2.8 to compile: clang -Wall -std=gnu99 -o <executable> <source.c>

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

This is true, but I am explicitly compiling gnu99 [which should support fcloseall ()], not c99. Although the code works, I do not like to have unresolved warnings when compiling. How can i solve this?

Edit : fixed type.

+4
source share
2 answers

To enable custom extensions, when you include standard headers, you need to define an appropriate function check macro. In this case, _GNU_SOURCE should work.

 #define _GNU_SOURCE #include <stdio.h> 

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

+4
source

Here on the man page fcloseall()

 #define _GNU_SOURCE #include <stdio.h> 

You must define the _GNU_SOURCE macros - this is a snippet, as well as the stdio.h header. _GNU_SOURCE is a function macro that is used to create a portable application.

+1
source

Source: https://habr.com/ru/post/1335402/


All Articles