Thread: Problems with timeval

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Problems with timeval

    Hi!
    I'm writing a function that uses the timeval structure but it gives me some problems...
    Here is the code:
    Code:
    #if defined(__unix__) || defined(unix)
    #include <time.h>
    #include <sys/time.h>
    #else	/* if win32 */
    #include <windows.h>
    #endif	/*   unix     */
    
    
    unsigned long get_msec(void) {
    #if defined(__unix__) || defined(unix)
    	//static struct 
    	struct timeval timev, first_timeval;
    	
    	gettimeofday(&timev, 0);
    
    	if(first_timeval.tv_sec == 0) {
    		first_timeval = timev;
    		return 0;
    	}
    	return (timev.tv_sec - first_timeval.tv_sec) * 1000 + (timev.tv_usec - first_timeval.tv_usec) / 1000;
    #else
    	return GetTickCount();
    #endif	/*   unix   */
    }
    And the errors I have:


    /Users/ermengol87/Documents/EPFL/Advance Computer Graphics/Prova Mandelbrot/../../../../Downloads/sdr_fract 2/timer.c:12:0 /Users/ermengol87/Documents/EPFL/Advance Computer Graphics/Prova Mandelbrot/../../../../Downloads/sdr_fract 2/timer.c:12: error: storage size of 'timev' isn't known


    /Users/ermengol87/Documents/EPFL/Advance Computer Graphics/Prova Mandelbrot/../../../../Downloads/sdr_fract 2/timer.c:12:0 /Users/ermengol87/Documents/EPFL/Advance Computer Graphics/Prova Mandelbrot/../../../../Downloads/sdr_fract 2/timer.c:12: error: storage size of 'first_timeval' isn't known

    I'm using OS X Snow Leopard and the last version of Xcode.

    I hope somebody help me!
    Last edited by Salem; 04-22-2010 at 08:51 AM. Reason: Added [code][/code] tags - learn to use them yourself (and read the intro threads)

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    #include <time.h>
    #include <sys/time.h>
    Why do you include both time.h files?

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    Why do you include both time.h files?
    That was just in a moment of desperation, because I couldn't make it work (and still is not working)

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You can do
    Code:
    gcc -E -o myfile.long myfile.c
    to see your code looks like after the preprocessor gets through with it. I don't have a Mac on me to test with at the moment, so I can't say what's in their <sys/time.h> or whether you need a certain #define. Even better, you can just say
    Code:
    man gettimeofday
    at your terminal and it will also say what you need.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM