I am writing a simple network program in C. When I turned on -Wall with --std=c11, I got an error message about the way am declaring a struct.
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int main() {
struct addrinfo res;
return 0;
}
The type addrinfo is defined in the sys/types.h file. I don't get an error when using a pointer.
How can I resolve this error message?
simple.c:9:25: error: storage size of ‘res’ isn’t known
struct addrinfo res;
^
Several points:
addrinfo is actually defined in netdb.h.-E flag to gcc to see the pre-processor output and discover that the addrinfo structure is actually not defined in your code. Now you should suspect that probably some definition is missing._POSIX_C_SOURCE feature test macro.So, this should resolve the mentioned error message:
#define _POSIX_C_SOURCE 200112L
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int main() {
struct addrinfo res;
return 0;
}
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