Archive 07/10/2020.

Unused parameters : __attribute__((unused))

michel_billaud

Not to be nitpicking about modern C++, but the attributes are the official way to declare a variable as unused

static int _board_handler(__attribute__((unused)) int argc, 
                          __attribute__((unused)) char **argv)
{
    puts(RIOT_BOARD);
    return 0;
}

It makes the programmer’s intention much more explicit than (void) , and thus should be strongly encouraged.

The (void) thing trick was a workaround, before C++11 officially introduced __attribute__ annotations.


It is not (yet) part of the C standard, but is supported by the GNU gcc compiler as an extension (ie. works with gcc, but maybe not with other compilers).

Actually, there could be an “maybe_unused” keyword in the next C standard see 6.7.11.3 in
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2454.pdf

aabadie2

Hi,

Thanks for the advice.
I think this way of declaring unused variables could probably be used in RIOT but it’s not, for now, the usual way in the project.
So here, the sample code follows the convention in RIOT (which mainly follows C standard). The maybe_unused could be useful indeed.