Thread: compilation error comes with the declaration of timeval

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    22

    compilation error comes with the declaration of timeval

    Hi,
    I declared the struct time value and import the header sys/time.h also.
    but when compile the program it returns gives the error "/home/lsf/mesh_project/D5/src/lib/mcast.c|199|error: ‘timeval’ undeclared (first use in this function)|"

    my program is written as follows.
    Code:
    #include "mcast.h"
    #include "msgmcast.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <sys/param.h>
    #include <sys/time.h>
    #include <sys/select.h>
    #include <sys/types.h>
    #include <sys/unistd.h>
    
    // some methods which works fine
    
    
    int recvfromTimeOut(int socket, long sec, long usec)
    {
        // Setup timeval variable
        timeval timeout;
    
        timeout.tv_sec = sec;
       timeout.tv_usec = usec;
        // Setup fd_set structure
        fd_set fds;
        FD_ZERO(&fds);
        FD_SET(socket, &fds);
        // Return value:
        // -1: error occured
        // 0: timed out
        // >0: data ready to be read
        return select(0, &fds, 0, 0, &timeout);
    
    }
    what goes wrong with this. apreciate you time regarding this.
    thanks

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    You forgot the struct keyword infront of timeval.

    Code:
    struct timeval timeout

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    22
    thank you very much for pointing out my mistake. it works now. thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM