🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #176

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

#176
From: fir
Date: Sun, 11 Oct 2026 07:08
48 lines
3191 bytes
bart pisze:
> On 10/10/2026 22:02, fir wrote:
>> i must have asked for that but i got somewhat holes im my memory and i 
>> dont exactly remember sometimes on which i wrote and on which not
>>
>> the problem is i need this adhos enums strongly and really, but those 
>> 'smth' are to shore i could use two of them f('some','thin') but it gets
>> uglier and such code is like degraded
>>
>> in fact there could be quite easy solution - it is use string literals 
>> as such tags - i mean you dont need to use strcomp , you just need to
>> have same string literals have same pointer then
>>
>> if("cat" == "cat") will return true and
>> if("cat" == "dog") will return false
> 
> Identical string literals, both visible in the same C source file, MIGHT 
> have the same pointer value.
> 
> But there is also runtime string data; strings returned from external 
> functions, or somehow synthesised at runtime, strings pointing into data 
> structures etc, that will not have the same address even two strings are 
> the same.
> 
> This would be up to you to produce, for example create a function call 
> 'intern' that takes a string and returns a unique index for each unique 
> string.
> 
> Then:
> 
>     if (intern(S) == intern(T))
> 
> will be guaranteed true if S and T are in fact same. But as it is, 
> 'intern' will be doing string comparison and more. You might as well 
> create a function 'eqstring(S, T)' that returns 'strcmp(S, T) == 0'.
> 
>> (if that would be 'unlocked' in language, then side effect woudl be 
>> string literals could be usad as tags (adhoc enums)
> 
> It really sounds like need a higher level language than C. Try Python 
> where you just write:
> 
>     if S == T:
> 
> and it will work exactly as you want.
> 
> 
its not higher level i would say its lower lewel than old c
Technical Details
Message-ID: <11afclv$2dli3$2@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> <11aeae9$23lek$1@dont-email.me>

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:46 +0200
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <11afclv$2dli3$2@dont-email.me>
References: <11ae962$2365v$1@dont-email.me> <11aeae9$23lek$1@dont-email.me>
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:48 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2545219"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18PhYx/GjeC7mTv8x9/x41wuFekMeSOT3Y="; 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:XGLm6NEMU9b4Su/UdrAHm2PgyXQ= sha256:n0hmGgwILswuWW5Rd53ze0FQR2y1OzGEek7Movh9JMk=
	sha1:0qk6I4KyzpFU7QkD1X+bBw3X6D0= sha256:QpZDf5NyW/vQ3YrETSyJwb9dy/NdQdOeuhYqsvy+6qc=
In-Reply-To: <11aeae9$23lek$1@dont-email.me>