0

Using an admittedly old compiler, I'm trying to compile code that uses functions like nan(), swprintf(), and other C99 features. I add the -std=c99 argument to CFLAGS, and those issues get fixed, but now I'm seeing

warning: implicit declaration of function ‘gmtime_r’

I tried following the advice in implicit declaration of function ‘gmtime_r’, but it didn't help.

Did gmtime_r() get removed from C99 or something?


Here's a tiny test program:

#include <math.h>
#include <time.h>

int
main(int argc, char **argv)
{
    double x;
    time_t t;
    struct tm tm;

    x = nan("0");
    t = time(NULL);
    gmtime_r(&t, &tm);

    return 0;
}

And the results of trying to compile it:

$ cc --version
cc (Ubuntu 4.3.3-5ubuntu4) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cc -c foo.c
foo.c: In function ‘main’:
foo.c:12: warning: incompatible implicit declaration of built-in function ‘nan’

$ cc -c -std=c99 foo.c
foo.c: In function ‘main’:
foo.c:14: warning: implicit declaration of function ‘gmtime_r’
Edward Falk
  • 9,991
  • 11
  • 77
  • 112
  • 1
    I don't think `gmtime_r` was ever in any version of the ANSI or ISO C standard. Your compiler without `-std=c99` probably provides it as a non-ISO extension, but it may be that with `-std=c99` it hews strictly to the standard and switches off all non-standard extensions. – Nate Eldredge Aug 15 '22 at 21:02
  • For more help, how about a [mcve] together with details on your compiler command line, C library version, OS etc. – Nate Eldredge Aug 15 '22 at 21:04
  • Concur with @NateEldredge gmtime_r was not and is not standard C. Instead try `-std=gnu99` to get C99 with GNU extensions (assuming a suitable version of glibc, because this is implemented mostly in the library not the compiler) i.e. the C99 counterpart of the gnu89 you probably get by default. – dave_thompson_085 Aug 16 '22 at 04:13
  • I want the source cod to be compatible with Mac and Windows as well. Probably simplest to not use gmtime_r(). Thanks for your advice everybody. – Edward Falk Aug 16 '22 at 16:58

0 Answers0