public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Jędrzej Dudkiewicz" <jedrzej.dudkiewicz@gmail.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Compiler message -Wunused confusion
Date: Thu, 15 Feb 2024 16:31:02 +0100	[thread overview]
Message-ID: <CABJqhQO8U7fbWFecwqLMiBhyDH-nEmUq38ZxXtBDH08=CpJX-Q@mail.gmail.com> (raw)
In-Reply-To: <20240214124123.GC19790@gate.crashing.org>

[-- Attachment #1: Type: text/plain, Size: 900 bytes --]

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.

  reply	other threads:[~2024-02-15 15:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 11:11 A. Mc.
2024-02-14 12:41 ` Segher Boessenkool
2024-02-15 15:31   ` Jędrzej Dudkiewicz [this message]
2024-02-14 12:44 ` David Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABJqhQO8U7fbWFecwqLMiBhyDH-nEmUq38ZxXtBDH08=CpJX-Q@mail.gmail.com' \
    --to=jedrzej.dudkiewicz@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).