0

I am trying to use gettimeofday64() instead of gettimeofday() function.

 #include <time.h>
 #include <stdio.h>

 int main () {
    struct timeval64 tim;
    int ret = gettimeofday64(&tim, NULL);

    printf("Ret = %d\n", ret);

 return 0;
 } 

Getting compilation error:
day.cpp: In function ‘int main()’:
day.cpp:5: error: aggregate ‘timeval64 tim’ has incomplete type and cannot be defined
day.cpp:6: error: ‘gettimeofday64’ was not declared in this scope

The same code works when used getimeofday() with header #include <sys/time.h> Why i am getting error for using gettimeofday64()?

Savita
  • 75
  • 4
  • 1
    If your implementation has gettimeofday64() (perhaps it *DOESN'T*), then `` should be the header you need. – paulsm4 Apr 03 '23 at 08:55
  • Because `gettimeofday64` is not part of `time.h`? `time.h` is the standard library header and `gettimeofday64` is not a standard library function. – Jeroen Mostert Apr 03 '23 at 08:56
  • 1
    [This manual page](https://www.unix.com/man-page/osf1/2/gettimeofday64/) state that the `gettimeofday64` function declaration is "only available when the `_TIME64_T` feature macro is defined during compilation." It also mentions the `` header file. And you need to define the macro *before* you include the header file. And note that it's not a universally available function, your system might simply not have it. – Some programmer dude Apr 03 '23 at 08:57
  • 1
    Q: Can you please elaborate how to fix? A: What part of `"gettimeofday64() might not be available for your platform/your C runtime library/your C development environment"` don't you get??? Out of curiousity: a) what is your platform? b) which C compiler are you using? c) Did you try looking at your compiler's "sys/time.h" file? Did it have any references to "gettimeofday64"? – paulsm4 Apr 03 '23 at 20:37

0 Answers0