[MINC-development] Where to add generic new private macro?
Sean McBride
sean at rogue-research.com
Thu Jan 16 14:44:13 EST 2014
Hi all,
I'm working on fixing warnings in MINC as shown by the ITK dashboard.
I have a fix for the print_error() function, which is a printf-like thing. I need to add the following somewhere, but don't know where:
/* To allow gcc and clang to warn upon mismatch of format string and parameters. */
#if !defined(MINC_FORMAT_FUNCTION)
#if defined(__GNUC__) && (__GNUC__ >= 4)
#define MINC_FORMAT_FUNCTION(func, p1, p2) __attribute__((format(func, p1, p2)))
#else
#define MINC_FORMAT_FUNCTION(func, p1, p2)
#endif
#endif
then I can change print_error() to be declared like so:
VIOAPI void print_error( char format[], ... ) MINC_FORMAT_FUNCTION(printf, 1, 2);
That'll fix a warning and allow gcc/clang to check uses of print_error() itself and give additional warnings like:
libminc/volume_io/Prog_utils/alloc.c:247:62: warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
print_error( "Cannot alloc 1D array of %d bytes.\n", n_bytes );
~~ ^~~~~~~
%lu
Where should I put this MINC_FORMAT_FUNCTION macro? It could be useful throughout minc, so maybe some kind of header that's used everywhere?
Thanks,
--
____________________________________________________________
Sean McBride, B. Eng sean at rogue-research.com
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
More information about the MINC-development
mailing list