From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 5B5063857011 for ; Wed, 14 Feb 2024 12:42:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B5063857011 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.crashing.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5B5063857011 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=63.228.1.57 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707914548; cv=none; b=CbIc/FsyjrsU9jkrBdfrdD51AIsdVvMgSIipTNilqe4DaxFHR90KKQhfFshS3Cat/jz3xZV7JeBQx7rygaHEkPBPh4RhgeftRM6+AzEteSxhhtsjSBLP0QMAirEk6n75g7jrtoNsaJ573wkrmxOh7UtrGWhSt5CyAXxIp9Dn3L0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707914548; c=relaxed/simple; bh=pCyvOl5tWanbvD8+Ipu4cc4Tt0H7yIw3X8z2TfjP3i4=; h=Date:From:To:Subject:Message-ID:Mime-Version; b=es4GrC/agJGwhS0loQPXugGHg/WVI8aoBA9hq/wCd83h2Nlgr+zhStED9ZQaMXCeLQMzyyTe31MoFobT65cOaqtXDDBQK2+tMGQrhDkF0TEcVsIqgnR+XErlU8/l7sU1ojiVo1jzIvEQ4ezoRqwVVUrDBkWxRQNIJa6QqXjpHt0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 41ECfNlp030292; Wed, 14 Feb 2024 06:41:23 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 41ECfNiJ030291; Wed, 14 Feb 2024 06:41:23 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Wed, 14 Feb 2024 06:41:23 -0600 From: Segher Boessenkool To: "A. Mc." <47dragonfyre@gmail.com> Cc: gcc-help@gcc.gnu.org Subject: Re: Compiler message -Wunused confusion Message-ID: <20240214124123.GC19790@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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