From: Segher Boessenkool <segher@kernel.crashing.org>
To: "A. Mc." <47dragonfyre@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Compiler message -Wunused confusion
Date: Wed, 14 Feb 2024 06:41:23 -0600 [thread overview]
Message-ID: <20240214124123.GC19790@gate.crashing.org> (raw)
In-Reply-To: <CAOsti3=gO6mD2tFp4eqQ_K_tVSQrQ_AUvAOdV-KAG5jgjWD86A@mail.gmail.com>
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
next prev parent reply other threads:[~2024-02-14 12:42 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 [this message]
2024-02-15 15:31 ` Jędrzej Dudkiewicz
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=20240214124123.GC19790@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=47dragonfyre@gmail.com \
--cc=gcc-help@gcc.gnu.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).