[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

_GL_ATTRIBUTE_FORMAT_PRINTF incorrect for non-glibc systems

From: Eli Zaretskii
Subject: _GL_ATTRIBUTE_FORMAT_PRINTF incorrect for non-glibc systems
Date: Sun, 12 Jun 2016 19:41:04 +0300

lib/stdio.in.h has this fragment:

     indicates to GCC that the function takes a format string and arguments,
     where the format string directives are the ones standardized by ISO C99
     and POSIX.  */
  #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
  # define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \
     _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, 

However, __gnu_printf__ is documented to refer to formats accepted by
the GNU C library, so it's potentially inappropriate on non-glibc
systems.  In particular, MinGW builds that use this definition of
_GL_ATTRIBUTE_FORMAT emit bogus compilation warnings, like this one:

  tfmt.c: In function 'foo':
  tfmt.c:13:39: warning: format '%d' expects argument of type 'int', but 
  3 has type 'long long int' [-Wformat=]
     return make_formatted_string (name, "F%" PRIdMAX, count);

because PRIdMAX is defined as "I64d" in the MinGW headers, and
__gnu_printf__ evidently doesn't recognize that specifier.

What's more serious, using __gnu_printf__ will not flag the use of
%lld for formatting long long values, which will cause run-time

Using __ms_printf__ instead of __gnu_printf__ makes these problems go
away in a MinGW build.

Bottom line, I don't think __gnu_printf__ should be used on non-glibc


reply via email to

[Prev in Thread] Current Thread [Next in Thread]