If you use -std=c99
, only functions that are strictly a part of the C99 standard are included by the header files. scandir()
is not in the C99 standard. Therefore, you have to set a preprocessor variable to ensure that the function prototype is included. For example, the man page for scandir()
indicates that setting the _BSD_SOURCE
or _SVID_SOURCE
preprocessor variables before you do the #include
will fix the problem. Or, you can use #define _GNU_SOURCE
which will in turn set quite a few different variables for you (including _BSD_SOURCE
and _SVID_SOURCE
).
Your code will still compile with the warning and work because C allows you to compile with implicitly defined functions, and the linker will correctly link the call to scandir()
to the proper function.