What does this statement mean in C: "(void)ptr;"

Viewed 508

It may not be clear from the title. I came across the following code in an embedded STM32 project. I don't understand the line inside the function.

    static void txend1(UARTDriver *uartp) {
        (void)uartp; // what does this do? Is it a statement?
    }

I've tried searching elsewhere online, but most results are casting pointers to void pointers, which I don't think this is. Thanks for the help!

1 Answers

this is just a portable way to suppress the warning on this unused uart parameter.

It has no effect, but compilers see that as used, and don't issue any warning.

Very useful when the prototype of the function is imposed / cannot be changed (callback function) but your implementation doesn't need this parameter.

(note that gcc favors the __attribute__((unused)) construct, easier to understand, but not compatible with all compilers)

Related