🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #250

Re: compare literals / if( "cat"== "dog") {}

#250
From: Lew Pitcher
Date: Sun, 11 Oct 2026 23:08
31 lines
2332 bytes
I don't see fir's posts, so please pardon my replying to fir
in this manner

On Sun, 11 Oct 2026 18:28:51 +0000, MitchAlsup wrote:

> fir <profesor.fir@gmail.com> posted:
> -------------------
>> 
>> if("cat" == "cat") will return true and

Not necessarily. In reference to string literals (the "cat" and "cat" above),
the C standard notes that "it is unspecified whether these arrays are distinct
provided their elements have the appropriate values". (ISO/IEC 9899:2024 N3220
Working Draft, 6.4.5 String literals, point #7).


It is up to the compiler to determine whether it will store the second "cat"
string as a separate string from the first "cat" string. If it stores them
both in the same string, then ("cat" == "cat") will be true. However, if
it stores the second "cat" string literal separately from the first "cat"
string literal, then ("cat" == "cat") will be false.


>> if("cat" == "dog") will return false

[snip proper way to compare strings]

-- 
Lew Pitcher
"In Skills We Trust"
Not LLM output - I'm just like this.
Technical Details
Message-ID: <11ah4sk$3324o$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11ae962$2365v$1@dont-email.me> <1791743331-5857@newsgrouper.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Lew Pitcher <lew.pitcher@digitalfreehold.ca>
Newsgroups: comp.lang.c
Subject: Re: compare literals / if( "cat"== "dog") {}
Date: Sun, 11 Oct 2026 23:08:04 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 31
Message-ID: <11ah4sk$3324o$1@dont-email.me>
References: <11ae962$2365v$1@dont-email.me>
	<1791743331-5857@newsgrouper.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Oct 2026 23:08:05 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3246232"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+ZITkpN3Y4mpo2m8bVL3HdSAk8PmudaZk="; posting-host="9ab92f4d49c17bbf684b504b51d7427b"
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
 git://git.gnome.org/pan2)
Cancel-Lock: sha1:K6Zb6JDlSkTN5SX9MFPRPchcGbg= sha256:l/GhPwM6H4dXDMmtjA7mHdpf0WmaB946BbcMYcNk+14=
	sha1:/qAChbrk7Z5P25ScuckKolQGqDA= sha256:+bF6YE0WdzCQoGK6Vqsrp7JOnKGz5y7495L7UDsH4/s=