Article View: comp.lang.c
Article #146Re: compare literals / if( "cat"== "dog") {}
From: bart
Date: Sat, 10 Oct 2026 21:24
Date: Sat, 10 Oct 2026 21:24
46 lines
2931 bytes
2931 bytes
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.
Technical Details
Message-ID:
<11aeae9$23lek$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>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: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: compare literals / if( "cat"== "dog") {}
Date: Sat, 10 Oct 2026 22:24:26 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <11aeae9$23lek$1@dont-email.me>
References: <11ae962$2365v$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 10 Oct 2026 21:24:26 +0000 (UTC)
Injection-Info: dont-email.me;
logging-data="2217428"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Oah9feoFv4JsGZgN/ef6D"; posting-host="8d9c8b578a5ce6a1f662bc81cc091c91"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:0dhANb0qKPoBEZhrowKFhA3vL88= sha256:XvHi7C0Y6jnbI9CcAaPskXe5LkuNGiYS5Sa3LM3+2jk=
sha1:nz4f2BsLEjNpqH85fvKPcBd83T8= sha256:uuL2Vdii9wqEPGMhCfV71bWoeg8jZHvuKUyHMSbcDgo=
In-Reply-To: <11ae962$2365v$1@dont-email.me>
Content-Language: en-GB