Compiler message -Wunused confusion
Jędrzej Dudkiewicz
jedrzej.dudkiewicz@gmail.com
Thu Feb 15 15:31:02 GMT 2024
On Wed, Feb 14, 2024 at 1:42 PM Segher Boessenkool <
segher@kernel.crashing.org> wrote:
> On Wed, Feb 14, 2024 at 03:11:58AM -0800, A. Mc. via Gcc-help wrote:
> > 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.
>
What do you mean by "never uses foo again"? In each iteration foo is
compared to true and in each iteration it is flipped, so it should be true,
false, true, false and so on.
--
Jędrzej Dudkiewicz
I really hate this damn machine, I wish that they would sell it.
It never does just what I want, but only what I tell it.
More information about the Gcc-help
mailing list