On 10/25/2011 05:11 PM, Simson Garfinkel wrote:
Oh my goodness. Okay. Let me clarify my question.
1. What should I put in configure.ac?
2. Can you show me specifically how to instrument my function, for example,:
void my_crazy_error_printer(void *random_arg,const char *format,...)
void my_other_crazy_printer(const char *fmt,...)
Well, that all depends. Is your function my_crazy_error_printer going
to call the system printf (where it matters which parameters you pass,
and for cross-platform compatibility to mingw, you can't use %lld, %zu,
%1$s, or a number of other useful constructs), or is it only going to be
used with a printf replacement (such as gnulib) that guarantees POSIX
compliance?
If the answer is the former, then use:
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
# define ATTR_FORMAT(spec) __attribute__ ((__format__ spec))
#else
# define ATTR_FORMAT(spec) /* empty */
#endif
#define ATTR_FORMAT_PRINTF_SYSTEM(param, arg) \
ATTR_FORMAT ((__printf__, param, arg))
void my_other_crazy_printer(const char *fmt,...)
ATTR_FORMAT_PRINTF_SYSTEM(1,0)
and fix the warnings, because they are real bugs in the code (mingw
_will_ mishandle the format strings that gcc warned about).
If the answer is the latter, then use:
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
# define ATTR_FORMAT(spec) __attribute__ ((__format__ spec))
#else
# define ATTR_FORMAT(spec) /* empty */
#endif
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
# define ATTR_FORMAT_PRINTF(param, arg) \
ATTR_FORMAT ((__gnu_printf__, param, arg))
#else
# define ATTR_FORMAT_PRINTF(param, arg) \
ATTR_FORMAT ((__printf__, param, arg))
#endif
void my_other_crazy_printer(const char *fmt,...)
ATTR_FORMAT_PRINTF(1,0)
and because you promised gcc that your printer obeys POSIX rules,
whether compiled on Linux or mingw, gcc won't blink an eye at constructs
that mingw normally chokes on. On the other hand, it _will_ warn if you
try %I64d, as that is a non-portable mingw extension not present in glibc.
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org