I have the following code:
#include <stdio.h>
#include <time.h>
clock_t a;
void f(void) {
a = clock();
printf("in f(): %g\n", a);
}
void main(void) {
f();
printf("in main(): %g\n", a);
}
Compiling it with MinGW gcc and running it produces output similar to this:
in f(): -1.#QNAN
in main(): 1.49845e-307
Question: Why does a
contain -1.#QNAN
? While I understand what it means, I do not see what went wrong in the code. At first, I speculated that it has something to do with the printing format specifier for type clock_t
, but answers from this stackoverflow thread says otherwise. Even to make sure, I did a quick digging in the standard headers and found out that clock_t
is a typedef for long
(at least on my machine), which means that there is nothing wrong with regards to displaying the value. Could it be a bug in the clock()
function?
Edit: Just after reading the comments, I realized that my actual problem is that I was expecting a
to be some super small floating-point value so badly that I forgot clock_t
is, as I said, defined on my machine as of type long
. Sorry for the bother and thank you all for your time.