I have toy code that looks like this
#include <stdlib.h>
#include <unistd.h>
int main()
{
readlink("/proc/self/exe", "/my/path", 128);
return EXIT_SUCCESS;
}
When I compile with
icc main.c -o helloworld
everything is fine but when I e.g. try
icc -std=c99 main.c -o helloworld
or
icc -std=c11 main.c -o helloworld
I get the error message
main.c(6): warning #266: function "readlink" declared implicitly
What is it about c11 (or c99) standards that induces this error?
The definition is wrapped in
From the man page for
readlinkyou need to set the proper source definition first. The current POSIX definition can be set withgcc -std=c11 -D_POSIX_C_SOURCE=200809LIf you don't set everything correctly you get to hunt undefined behavior becausesizeof(int)andsizeof(void*)aren't the same anymore. Implicit declarations really did need to go for 64 bit to become.-std=gnu11flips everything on. If you don't have to care if you accidentally use a gcc extension or not, just set it in your makefile and forget about it.