timespec_get always returning zero nanoseconds and other problems

Started by karkon, March 09, 2015, 01:24:51 AM

Previous topic - Next topic

karkon

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#


#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.

frankie

Quote from: karkon on March 09, 2015, 01:24:51 AM
Hello, compiling the enclosed code witn Pelles C V8 RC7
Please update to last version V8-RC8

Quote from: karkon on March 09, 2015, 01:24:51 AM
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__:

#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>

This is not a bug.

Quote from: karkon on March 09, 2015, 01:24:51 AM
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.

Quote from: karkon on March 09, 2015, 01:24:51 AM
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.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

karkon

Thanks Frankie, just a couple of questions:
Quote from: frankie on March 09, 2015, 10:51:05 AM
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.

Quote from: frankie on March 09, 2015, 10:51:05 AM
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?


Bitbeisser

Quote from: karkon on March 10, 2015, 12:09:28 AMWhere 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

frankie

Quote from: karkon on March 10, 2015, 12:09:28 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