best practice to handle unused variables depending on macros

Mathieu Lacage mathieu.lacage@gmail.com
Mon Feb 6 18:15:00 GMT 2012


On Mon, Feb 6, 2012 at 18:34, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 6 February 2012 16:47, Mathieu Lacage wrote:
>>
>> Some of my collegues have started to add #ifdefs here and there in our
>> main code to handle these problems as they come. Others have been
>> advocating the use of macros that mark the problematic variables as
>> unused.
>
> That would be my choice:
>
> int __attribute__((unused)) var =
> some_function_whose_return_value_is_used_only_by_assert_macro();

Right. My collegues want to wrap that in a macro. Bwaaah.

> You could define the assert macro to do (void)sizeof(a) which would
> not evaluate the expression but which does count as "using" variables
> in the expression with current GCC (though don't assume GCC won't get
> smarter and warn about it in future)

Out of curiosity, would (void)sizeof(a) work with non-gcc compilers ?

Mathieu
-- 
Mathieu Lacage <mathieu.lacage@gmail.com>



More information about the Gcc-help mailing list