Re: Compiler message -Wunused confusion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 14, 2024 at 03:11:58AM -0800, A. Mc. via Gcc-help wrote:
> I am receiving the gcc compiler warning -Wunused-value computed not used. I
> can confirm this is true in my embedded application, the statement never
> switches. But I am completely confused as to why. It's essentially the
> following code:
> 
> volatile bool foo;
> 
> while (true) {
> if (foo == true){
>        //do something
>        foo = false;}
> else{
>        //do something else
>        foo = true;}
> }
> 
> Which never switches. What could be the cause of this?

Your code assigns to foo, but never uses foo again.  This is likely a
programming mistake, which is what the warning is for.

It is not that the compiler tells you to not do that.  If you want to
write code like that, you are free to do that, and the compiler will
correctly compile it.  If you have warning messages enabled
(-Wunused-value, enabled by -Wall for example) you get diagnostics like
this, where apparently you made a mistake in your programming.


Segher



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux