Article View: comp.lang.c
Article #177Re: compare literals / if( "cat"== "dog") {}
From: fir
Date: Sun, 11 Oct 2026 07:13
Date: Sun, 11 Oct 2026 07:13
54 lines
3494 bytes
3494 bytes
fir pisze:
> 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
why lower level? becouse in higher level they often like dont care for
some love level cases..so if c here dont cares on this tehnique of
using literals this way its like addition that care is lower level
Technical Details
Message-ID:
<11afcv3$2dli3$3@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> <11aeae9$23lek$1@dont-email.me> <11afclv$2dli3$2@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:13:38 +0200
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <11afcv3$2dli3$3@dont-email.me>
References: <11ae962$2365v$1@dont-email.me> <11aeae9$23lek$1@dont-email.me>
<11afclv$2dli3$2@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:13:40 +0000 (UTC)
Injection-Info: dont-email.me;
logging-data="2545219"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ppA6Gw0b+rMgNQUHkBUlcN5Yn8Rej+qI="; 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:SaS5OdCU5ZoQweMU7/MBGqaMRU4= sha256:c4o4hd8XJy/S6iRbo6iHN+2bgsOKUvW9gvOBsT2lLfg=
sha1:xplPg8avIB6l+V+cEtHUsbm0Sx4= sha256:PF01uaclsEY2uvS8g7aRv+I7CsDG1EV28/RYSYLYnqo=
In-Reply-To: <11afclv$2dli3$2@dont-email.me>