[MINC-development] Where to add generic new private macro?
Vladimir S. FONOV
vladimir.fonov at gmail.com
Thu Jan 16 19:45:14 EST 2014
Perhaps we should create a single header file with all these error handling functions ?
On 2014-01-16, at 5:36 PM, Andrew Janke <a.janke at gmail.com> wrote:
> Best bet is then probably libsrc/minc_private.h
>
> Vladimir, do you have a preference?
>
>
> a
>
> On 17 January 2014 08:31, Sean McBride <sean at rogue-research.com> wrote:
>> Andrew,
>>
>> Thanks for your reply. print_error() is just an example of a function that will need that decoration, there looks like there will be a few others too. That's why I thought it might make sense in some kind of general header that's included by most everything else (if there is such a thing).
>>
>> Sean
>>
>>
>> On Fri, 17 Jan 2014 08:25:49 +1000, Andrew Janke said:
>>
>>> 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,
>>
>>
> _______________________________________________
> MINC-development mailing list
> MINC-development at bic.mni.mcgill.ca
> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-development
---
Best regards,
Vladimir S. FONOV ~ v.s.fonov <at> ilmarin.info
More information about the MINC-development
mailing list