-
June 26th, 2011, 07:23 PM
#1
Getting problem with using struct timeval
Hi all,
I am us ing MS visual studio 2010 for compiling the C source code. While compiling I am getting the problem with header file time.h.The problem is , I get the error
"undefined reference to the suseconds_t" and some other syntactical error on the structure.
But the the structure timeval is defined as follows.
#ifndef _WINSOCK_H
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
I am passing this structure in the function named getTimeofDay(struct timeval *tv, struct timezone *tz) to get the elapse time. This function is defined
int getTimeof Day(struct timeval *tv, struct timezone *tz){
DWORD milliseconds;
milliseconds = timeGetTime();
tv->tv_sec =milliseconds/100;
tv->tv_usec =(milliseconds%1000)*1000;
return 0;
}
Once i change the DWORD with int long and time_t and suseconds_t with long , it compiles. Could you please let me know how can I get rid of this problem.
My operating system is Windows XP.
-
June 27th, 2011, 01:18 AM
#2
Re: Getting problem with using struct timeval
In Windows SDK, timeval is defined as
Code:
struct timeval {
long tv_sec;
long tv_usec;
};
See MSDN documentation: timeval Structure.
-
June 27th, 2011, 01:49 AM
#3
Re: Getting problem with using struct timeval
Do you think i need to enable SDK environment and need to include winsock2.h instead of time.h? Do you have any idea ?
-
June 27th, 2011, 03:05 AM
#4
Re: Getting problem with using struct timeval
There is no such a type suseconds_t in Windows. So you must either change it (or the whole structure) to something that exists in Windows, or #define (or typedef) it.
PS: you are not the first who has got this problem; see http://connect.microsoft.com/VisualS...six-conformant
Victor Nijegorodov
-
June 27th, 2011, 12:53 PM
#5
Re: Getting problem with using struct timeval
The problem is all about timing behviour.My source file includes time.h, which defines the structure timeval. The definition of timeval in the time.h is:
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
Do I need to change the include file?
I would like to be more precise in my problem. Once I load my source file into the visual studio 2010, I get the following error messages:
1.error: identifier DWORD is undentified .
2. error: identifier timeGetTime() is undefined.
3: error: identifier suseconds_t is undefined.
I am getting trouble with this for some days. Please let me know, how to overcome this problem?
-
June 27th, 2011, 01:12 PM
#6
Re: Getting problem with using struct timeval
Originally Posted by __bairagi
... Once I load my source file into the visual studio 2010, I get the following error messages:
1.error: identifier DWORD is undentified .
2. error: identifier timeGetTime() is undefined.
3: error: identifier suseconds_t is undefined.
I am getting trouble with this for some days. Please let me know, how to overcome this problem?
1. http://www.codeguru.com/forum/showthread.php?t=219341
3. See my previous post.
Victor Nijegorodov
-
June 27th, 2011, 01:45 PM
#7
Re: Getting problem with using struct timeval
Hi VictorN
Thanks for the reply. Yes you are right, I got rid of those error but i am encountering other errors like
rror C2011: 'timeval' : 'struct' type redefinition
I hope you could help me again.Thanks in advance.
-
June 27th, 2011, 01:52 PM
#8
Re: Getting problem with using struct timeval
Originally Posted by __bairagi
...
I hope you could help me again.Thanks in advance.
Sorry, I cannot.
Just because you didn't show you code...
Victor Nijegorodov
-
June 27th, 2011, 02:09 PM
#9
Re: Getting problem with using struct timeval
Hi,
The surprising thing is that I am getting error in header file.so,the snippet of code where the error has occured
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
in the header file time.h and the exact error is:
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(16): error C2011: 'timeval' : 'struct' type redefinition
-
June 27th, 2011, 03:00 PM
#10
Re: Getting problem with using struct timeval
What did you #include?
Which #if/#else/#endif do you have?
Victor Nijegorodov
-
June 27th, 2011, 03:34 PM
#11
Re: Getting problem with using struct timeval
Here are my includes.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
#ifdef HAVE_MMSYSTEM_H
#include <mmsystem.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
-
June 27th, 2011, 03:46 PM
#12
Re: Getting problem with using struct timeval
Originally Posted by __bairagi
Here are my includes.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
#ifdef HAVE_MMSYSTEM_H
#include <mmsystem.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
Great!
And if you meant that we here in the Forum already know how you defined all these:
HAVE_CONFIG_H
HAVE_WINDOWS_H
HAVE_MMSYSTEM_H
and what the "config.h" is
...
then you were wrong.
Victor Nijegorodov
-
June 27th, 2011, 03:52 PM
#13
Re: Getting problem with using struct timeval
Originally Posted by __bairagi
The surprising thing is that I am getting error in header file.so,the snippet of code where the error has occured
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
in the header file time.h and the exact error is:
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(16): error C2011: 'timeval' : 'struct' type redefinition
Hmm.. The strange thing is that in my VS2010 installation time.h file is in
\Microsoft Visual Studio 10.0\VC\include
and NOT in
\Microsoft Visual Studio 10.0\VC\include\sys
Also, it doesn't have your definition of timeval; it has:
Code:
/*
* Structure used in select() call, taken from the BSD file sys/time.h.
*/
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
June 27th, 2011, 05:09 PM
#14
Re: Getting problem with using struct timeval
Hello VladimirF,
Thanks for your reply. Actually I am newbie in MS visual studio. I have source files which i want to compile in MSVS. I may be missing some basic stuffs, so please let me know what are the stupids I am doing. I have been trying to solve it since few days, but not able to do.
-
June 28th, 2011, 12:39 AM
#15
Re: Getting problem with using struct timeval
It looks like some "cross-platform" source code wrtitten by a *nix-guy.
suseconds_t is a *NIX (linux) specific type.
You have to add the right preprocessor definitions in the project properties in order to choose the right headers for Windows.
For example, probably HAVE_WINDOWS_H has to be defined.
May be others but without seeing all the project code / properties, none can even guess.
Besides.
Are you using VS Express Edition? If yes, have you installed the right SDK?
Last edited by ovidiucucu; June 28th, 2011 at 12:53 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|