Article View: comp.lang.c
Article #175Re: compare literals / if( "cat"== "dog") {}
From: fir
Date: Sun, 11 Oct 2026 07:08
Date: Sun, 11 Oct 2026 07:08
26 lines
2280 bytes
2280 bytes
Johann 'Myrkraverk' Oskarsson pisze:
> On 10/11/2026 5:02 AM, fir wrote:
>> if("cat" == "cat") will return true and
>> if("cat" == "dog") will return false
>>
>>
>> i probably asked that but if so once again
>>
>> is there way to enforce it to work?
>
> Sort of. If you're /only/ comparing literals, you can apply the /GF
> switch in MSVC, and then all the literals will compiled into a single
> pool, and you can compare by the pointers.
>
> Of course, the pointers still point to the pool, and that's important
> to remember.
>
> I'm sure GCC and clang have equivalent switches.
there is -megre-constants but im not sure if it 1) will guarantee (at
least ractically) that it will work 2) if it will work at least in my
own case
i could eventually write a wrapper tag_eq(char*, char*) or something
which will be comparing by == and != and have fallback ino strcomp
eventually, possibly its worth trying
Technical Details
Message-ID:
<11afcku$2dli3$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-mailReferences:
<11ae962$2365v$1@dont-email.me> <9tyyS.21373$VDn8.13923@fx14.ams4>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: fir <profesor.fir@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: compare literals / if( "cat"== "dog") {}
Date: Sun, 11 Oct 2026 09:08:13 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <11afcku$2dli3$1@dont-email.me>
References: <11ae962$2365v$1@dont-email.me> <9tyyS.21373$VDn8.13923@fx14.ams4>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Oct 2026 07:08:15 +0000 (UTC)
Injection-Info: dont-email.me;
logging-data="2545219"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VGuzBBj7p23IQl+iz57y1HYys9ek73VA="; posting-host="c78a7ee27a315dc33fa20d18f85fce92"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:Pbby2J2uyJ+2bhmClYVV9kl9+NE= sha256:1lD2V1aJWrzUoBLEjlEj4/eEmo82sMV60lwhJoz5iN8=
sha1:T1sEKXiYb4s222JYC23+u2yajBA= sha256:0FYnOvafrbmMWmLdZQu3a2AB1SVEPry1JysaOhFgddI=
In-Reply-To: <9tyyS.21373$VDn8.13923@fx14.ams4>