The MSVC <time.h> header file defines the following functions as
'static inline':

  difftime
  gmtime
  localtime
  mktime
  time
  timespec_get

According to ISO C 23 § 6.7.5.(3), such functions cannot be used in non-static
inline functions:

  "An inline definition of a function with external linkage shall not
   contain ... a reference to an identifier with internal linkage."

gcc and clang give warnings about it:

$ cat foo.c
static inline int twice (int x) { return 2 * x; }
inline int foo (int x) { return twice (x); }

$ gcc -Wall -c foo.c
foo.c:2:33: warning: ‘twice’ is static but used in inline function ‘foo’ which 
is not static
    2 | inline int foo (int x) { return twice (x); }
      |                                 ^~~~~

$ clang -Wstatic-in-inline -c foo.c
foo.c:2:33: warning: static function 'twice' is used in an inline function with 
external linkage [-Wstatic-in-inline]
    2 | inline int foo (int x) { return twice (x); }
      |                                 ^

But this warning seems to be harmless. I cannot produce an undefined-symbol
error or some other weird behaviour, neither with gcc, nor with MSVC, nor
with clang.

So, it seems to me that when the 'static' definition is the same in all
compilation units, there is nothing to warn about, and we can ignore the
warning.

Bruno




Reply via email to