I am using GCC 4.9 on ubuntu 15.04. I am coding in eclipse CDT. This is a C program with the dialect set to c99. For some reason my compiler keeps warning me about this...
warning: implicit declaration of function ‘posix_memalign’ [-Wimplicit-function-declaration]
I am not sure why. I have #include<stdlib.h>
at the top and when I use eclipse the ctrl+click posix_memalign it takes me to the function declaration in stdlib.h. Why am I getting this warning?
I just tried changing the dialext to std=gnu99 and this fixed the issue. Is posix_memalign not included with c99?
The #define _POSIX_C_SOURCE 200809L
and other feature test macros have to be defined before any #include
lines.
This is because the macros tell the standard C library headers which features it should provide in addition/instead of the standard C library features; the features are "locked" at the point of #include
.
posix_memalign()
is provided by stdlib.h
, but only if POSIX.1-2001 or later are enabled; this means defining _POSIX_C_SOURCE
as 200112L
or larger (the L is there because it is an integer constant of long
type), or _XOPEN_SOURCE
with 600
or larger.
The error shown only occurs when
The macros were not defined when stdlib.h
was included
or
stdlib.h
was not included
or
The C library implementation does not provide POSIX.1 features
Using GCC in Ubuntu, it has to be one of the first two, because the C library most definitely does provide these POSIX.1 features.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With