For a peripheral requirement in an embedded system, I have to declare a variable to read a register, but won't use the value later. Hence, I get compiler warning about my unused variable naturally. How can I suppress the warning? I have 2 ways in mind:
adding a dummy read from variable, like:
volatile int var;
var = peripheral_register;
var = var;
Do you have a better idea?
If all you need to do is read the register (to clear some status flag for example), then you do not need a receiving variable at all just:
(void)peripheral_register ;
is sufficient assuming the register is itself is declared volatile so that it must be read.
Otherwise you could make your dummy var
global with external linkage - that way the compiler cannot determine that it is not read elsewhere; but that's a far uglier solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With