[MINC-development] Where to add generic new private macro?
Andrew Janke
a.janke at gmail.com
Thu Jan 16 17:25:49 EST 2014
Hi Sean,
Looks like you have having hilarious fun. Given the print_error macro
is a David McDonald harbinger and restricted to volume_io it probably
makes sense to just put your macro above that of print_error.
minc2 itself does errors differently (libsrc2/minc2_error.c), this in
itself looks like a re-implementation of perror and friends but I
digress.
a
On 17 January 2014 05:44, Sean McBride <sean at rogue-research.com> wrote:
> 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
>
>
> _______________________________________________
> MINC-development mailing list
> MINC-development at bic.mni.mcgill.ca
> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-development
More information about the MINC-development
mailing list