NO

Author Topic: timespec_get always returning zero nanoseconds and other problems  (Read 5026 times)

karkon

  • Guest
Hello, compiling the enclosed code witn Pelles C V8 RC7 with the following options:

-std:C11 -Tx64-coff -MT -Ot -Ob1 -fp:precise -W1 -Gr#

Code: [Select]
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
struct timespec Time;
char string[100];
while ((string[0]!='Q')&&(string[0]!='q')){
timespec_get(&Time,TIME_UTC);
printf("seconds=%ld, nanoseconds=%ld",Time.tv_sec,Time.tv_nsec);
printf("\nEnter something starting with 'Q' to quit:\n");
gets_s(string,sizeof(string));
}
return 0;
}

The compiler says warning #2018: Undeclared function 'gets_s'. I have verified that the function is properly defined in stdio.h. The linker finds the function without problems.

The timespec_get function always returns zero nanoseconds as can be seen by running the sample program. However the _ftime function works ok.

Finally, if the option -MT is removed then the linker doesn't find the timespec_get function.

I am linking with the following options:

-subsystem:console -machine:x64 kernel32.lib advapi32.lib delayimp64.lib

The test was performed under Windows 8.1 64.
« Last Edit: March 09, 2015, 01:36:04 AM by karkon »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: timespec_get always returning zero nanoseconds and other problems
« Reply #1 on: March 09, 2015, 10:51:05 AM »
Hello, compiling the enclosed code witn Pelles C V8 RC7
Please update to last version V8-RC8

The compiler says warning #2018: Undeclared function 'gets_s'. I have verified that the function is properly defined in stdio.h. The linker finds the function without problems.
You're right iit is defined in stdio.h, but you have not look carefully enaugh, to enable the safe functions you have to define the symbol __STDC_WANT_LIB_EXT1__:
Code: [Select]
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
This is not a bug.

The timespec_get function always returns zero nanoseconds as can be seen by running the sample program. However the _ftime function works ok.
As specified in the help the resolution of timespec_get, that is available only when compiling in C11 mode, depends on machine clock resolution. In windows the min resolution is 1mS. _ftime works differently, but anyway don't give nS resolution.
This is not a bug.

Finally, if the option -MT is removed then the linker doesn't find the timespec_get function.
It seems that the function is missing in the single threaded lib, I can't say if this is a bug or a planned behaviour.
« Last Edit: March 09, 2015, 10:52:50 AM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

karkon

  • Guest
Re: timespec_get always returning zero nanoseconds and other problems
« Reply #2 on: March 10, 2015, 12:09:28 AM »
Thanks Frankie, just a couple of questions:
Please update to last version V8-RC8

Where can I find V8-RC8? The last version I find in http://www.pellesc.de is V8-RC7.

As specified in the help the resolution of timespec_get, that is available only when compiling in C11 mode, depends on machine clock resolution. In windows the min resolution is 1mS. _ftime works differently, but anyway don't give nS resolution.

Well, the problems is that timespec_get always returns zero nanoseconds. Help says  the tv_nsec member is set to the integral number of nanoseconds, rounded to the resolution of the system clock. My computer (Sony VAIO) surely has more than one second resolution, and in fact  I get better than 1 ms resolution with _ftime. Am I missing something?

Offline Robert

  • Member
  • *
  • Posts: 247
Re: timespec_get always returning zero nanoseconds and other problems
« Reply #3 on: March 10, 2015, 01:22:57 AM »
Thanks Frankie, just a couple of questions:
Where can I find V8-RC8? The last version I find in http://www.pellesc.de is V8-RC7.

http://forum.pellesc.de/index.php?topic=6634.0

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: timespec_get always returning zero nanoseconds and other problems
« Reply #4 on: March 10, 2015, 02:55:00 AM »
Where can I find V8-RC8? The last version I find in http://www.pellesc.de is V8-RC7.
Check the "Announcement" section of this forum, the official download location has always been Pelle's http://www.smorgasbordet.com/pellesc/download.htm

Ralf

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: timespec_get always returning zero nanoseconds and other problems
« Reply #5 on: March 10, 2015, 10:57:23 AM »
Well, the problems is that timespec_get always returns zero nanoseconds. Help says  the tv_nsec member is set to the integral number of nanoseconds, rounded to the resolution of the system clock. My computer (Sony VAIO) surely has more than one second resolution, and in fact  I get better than 1 ms resolution with _ftime. Am I missing something?
You're right  :)
This implementation is partial, I think inserted for the sake of C11 compliance, it has only one base defined that is TIME_UTC=1Second.
With such resolution the integral value  the ns member is always 0.
If you need very high resolution consider using  QueryPerformanceCounter that is based on processor clock.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide