jsan
jsan

Reputation: 1057

C++ Error this declaration has no storage class or type specifier

I'm trying to setup a timeout for the select(int, fd_set, fd_set) function for UDP socket connections.

When i setup the second and usecond variables, I get Error this declaration has no storage class or type specifier.

Here's the code

#define UTIMER 300000
#define STIMER 0 
struct timeval timeouts;
timeouts.tv_sec=STIMER;    // <-- ERROR HERE
timeouts.tv_usec=UTIMER;   // <-- ERROR HERE

Upvotes: 0

Views: 17336

Answers (1)

kfsone
kfsone

Reputation: 24259

The problem is that you haven't #included the header which defines timeval. The struct timeval timeouts is essentially a prototype declaration. It provides enough information for the compiler to know the variable exists and allow you to, for example, use it in pointer operations, with type information about the pointer (that it points to a struct timeval).

But it doesn't yet know what the inside of it looks like.

If this is Windows, you need to #include <Winsock2.h>; Linux #include <sys/time.h>

Upvotes: 4

Related Questions