On 10/25/2011 03:52 PM, Simson Garfinkel wrote:
I have code that trips the warning:
warning: function might be possible candidate for ‘printf’ format attribute
Unfortunately, mingw uses a different declaration for saying something is printf like
than gcc does running on MacOS and Linux.
Is there a way to do the declaration in a portable manner?
Projects that use gnulib don't have a problem. Gnulib solved this issue
with the following preprocessor goop in a self-built <stdio.h> file that
it builds to wrap the system <stdio.h>:
/* _GL_ATTRIBUTE_FORMAT_PRINTF
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,
first_argument))
#else
# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter,
first_argument) \
_GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter,
first_argument))
#endif
/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF,
except that it indicates to GCC that the supported format string
directives
are the ones of the system printf(), rather than the ones
standardized by
ISO C99 and POSIX. */
#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter,
first_argument) \
_GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter,
first_argument))
then it makes configure-time decisions on whether to use
_GL_ATTRIBUTE_FORMAT_PRINTF or _GL_ATTRIBUTE_FORMAT_PRINTF according to
whether the package requested the gnulib modules to override printf to
fix implementation bugs, or whether the package just wants the system
functionality (and is steering clear of the buggy constructs).
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org