0

Sample code (t667c.c, taken from here):

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

int main(void)
{
    struct timespec ts;
    timespec_get(&ts, TIME_UTC);
    char buff[100];
    strftime(buff, sizeof buff, "%D %T", gmtime(&ts.tv_sec));
    printf("Current time: %s.%09ld UTC\n", buff, ts.tv_nsec);
    return 0;
}

Invocation:

$ gcc t667c.c -std=c11 -pedantic -Wall -Wextra
t667c.c: In function ‘main’:
t667c.c:7:5: warning: implicit declaration of function ‘timespec_get’ [-Wimplicit-function-declaration]
    7 |     timespec_get(&ts, TIME_UTC);
      |     ^~~~~~~~~~~~
t667c.c:7:23: error: ‘TIME_UTC’ undeclared (first use in this function)
    7 |     timespec_get(&ts, TIME_UTC);
      |                       ^~~~~~~~
t667c.c:7:23: note: each undeclared identifier is reported only once for each function it appears in

Extra:

$ gcc --version
gcc (GCC) 11.2.0

$ uname -a
CYGWIN_NT-10.0 xxx 3.3.4(0.341/5/3) 2022-01-31 19:35 x86_64 Cygwin

Does it mean that TIME_UTC and timespec_get are not supported?


UPD. See UPD in the similar question.

4
  • 1
    Since this is not your first question regarding cygwin: Cygwin seems to use newlib as libc implementation, see cygwin.com/faq.html#faq.programming.glibc. That is a very minimal implementation of the C standard library. I wouldn't be surprised if it doesn't implement a lot of especially the newer features. The readme even says that it is an "ANSI C library" (sourceware.org/newlib/README). Commented Mar 2, 2022 at 15:19
  • @user17732522 Thanks! How to determine the version of newlib? Is there a corresponding macro? Commented Mar 2, 2022 at 16:23
  • 1
    From what I can tell __NEWLIB__ and __NEWLIB_MINOR__. But I don't know how heavily modified the cygwin version is. Repository seems to be here: cygwin.com/git/?p=newlib-cygwin.git;a=summary Commented Mar 2, 2022 at 16:31
  • Put all your options before your source files. E.G. gcc -std=c11 -pedantic -Wall -Wextra t667c.c, since some options are handled left to right. Commented Mar 4, 2022 at 17:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.