timespec

timespec on windows compilers

大城市里の小女人 提交于 2019-12-20 03:10:58
问题 On posix it is possible to use timespec to calculate accurate time length (like seconds and milliseconds). Unfortunately I need to migrate to windows with Visual Studio compiler. The VS time.h library doesn't declare timespec so I'm looking for other options. As far as could search is it possible to use clock and time_t although I could't check how precise is counting millisecons with clock counting. What do you do/use for calculating time elapse in a operation (if possible using standards c+

Convert milliseconds to timespec for GNU port

匆匆过客 提交于 2019-12-08 17:10:07
问题 I want to convert milliseconds into timespec structure used by GNU Linux. I have tried following code for the same. timespec GetTimeSpecValue(unsigned long milisec) { struct timespec req; //long sec = (milisecondtime /1000); time_t sec = (time_t)(milisec/1000); req->tv_sec = sec; req->tv_nsec = 0; return req; } Running this code gives me the following error. expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘GetTimeSpecValue’ I have also include time.h file in the code. 回答1: The

Is there a standard way to convert a struct timeval into a struct timespec?

我只是一个虾纸丫 提交于 2019-12-05 15:23:09
问题 struct timeval represents and instant in time with two members, tv_sec (seconds) and tv_usec (microseconds). In this representation, tv_usec is not by itself an absolute time it is a sub second offset off of tv_sec . struct timespec works the same way except that instead of microseconds it's offset ( tv_nsec ) is stored in nanosecond units. The question is: Is there a standard way to convert between these two? 回答1: Looking at this doc, I would think multiplying tv_usec by 1000 is sufficient

Is there a standard way to convert a struct timeval into a struct timespec?

↘锁芯ラ 提交于 2019-12-04 01:34:47
struct timeval represents and instant in time with two members, tv_sec (seconds) and tv_usec (microseconds). In this representation, tv_usec is not by itself an absolute time it is a sub second offset off of tv_sec . struct timespec works the same way except that instead of microseconds it's offset ( tv_nsec ) is stored in nanosecond units. The question is: Is there a standard way to convert between these two? Looking at this doc , I would think multiplying tv_usec by 1000 is sufficient to get tv_nsec . More important, I suspect is the source of the different structures: they could be filled

timespec on windows compilers

99封情书 提交于 2019-12-02 02:02:19
On posix it is possible to use timespec to calculate accurate time length (like seconds and milliseconds). Unfortunately I need to migrate to windows with Visual Studio compiler. The VS time.h library doesn't declare timespec so I'm looking for other options. As far as could search is it possible to use clock and time_t although I could't check how precise is counting millisecons with clock counting. What do you do/use for calculating time elapse in a operation (if possible using standards c++ library) ? Grim The function GetTickCount is usually used for that. Also a similiar thread: C++

Timespec redefinition error [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-11-27 19:53:43
This question already has an answer here: Timespec :struct type Error c2011 4 answers While executing a Pthread program in C using Visual Studio 2015, I got the following error: Error C2011 'timespec': 'struct' type redefinition The following is my code: #include<pthread.h> #include<stdlib.h> #include<stdio.h> void *calculator(void *parameter); int main(/*int *argc,char *argv[]*/) { pthread_t thread_obj; pthread_attr_t thread_attr; char *First_string = "abc"/*argv[1]*/; pthread_attr_init(&thread_attr); pthread_create(&thread_obj,&thread_attr,calculator,First_string); } void *calculator(void

Timespec redefinition error [duplicate]

情到浓时终转凉″ 提交于 2019-11-26 19:55:04
问题 This question already has answers here : Timespec :struct type Error c2011 (5 answers) Closed 3 years ago . While executing a Pthread program in C using Visual Studio 2015, I got the following error: Error C2011 'timespec': 'struct' type redefinition The following is my code: #include<pthread.h> #include<stdlib.h> #include<stdio.h> void *calculator(void *parameter); int main(/*int *argc,char *argv[]*/) { pthread_t thread_obj; pthread_attr_t thread_attr; char *First_string = "abc"/*argv[1]*/;

GCC with -std=c99 complains about not knowing struct timespec

*爱你&永不变心* 提交于 2019-11-26 17:41:38
When I try to compile this on Linux with gcc -std=c99 , the compiler complains about not knowing struct timespec . However if I compile this without -std=c99 everything works fine. #include <time.h> int main(void) { struct timespec asdf; return 0; } Why is this and is there a way to still get it to work with -std=c99 ? Explicitly enabling POSIX features The timespec comes from POSIX, so you have to 'enable' POSIX definitions: #if __STDC_VERSION__ >= 199901L #define _XOPEN_SOURCE 600 #else #define _XOPEN_SOURCE 500 #endif /* __STDC_VERSION__ */ #include <time.h> void blah(struct timespec asdf)

GCC with -std=c99 complains about not knowing struct timespec

有些话、适合烂在心里 提交于 2019-11-26 05:34:36
问题 When I try to compile this on Linux with gcc -std=c99 , the compiler complains about not knowing struct timespec . However if I compile this without -std=c99 everything works fine. #include <time.h> int main(void) { struct timespec asdf; return 0; } Why is this and is there a way to still get it to work with -std=c99 ? 回答1: Explicitly enabling POSIX features The timespec comes from POSIX, so you have to 'enable' POSIX definitions: #if __STDC_VERSION__ >= 199901L #define _XOPEN_SOURCE 600