Article View: comp.lang.c
Article #207Re: compare literals / if( "cat"== "dog") {}
From: fir
Date: Sun, 11 Oct 2026 11:00
Date: Sun, 11 Oct 2026 11:00
80 lines
3992 bytes
3992 bytes
fir pisze:
> fir pisze:
>> fir pisze:
>>> ai answered that so maybe this is final version
>>>
>>>
>>> #include <stdint.h>
>>>
>>> typedef const char tag[20] __attribute__((aligned(4)));
>>>
>>> static inline int tag_eq(tag a,tag b)
>>> {
>>> if(a==b) return 1;
>>>
>>> const uint32_t *x=(const uint32_t *)a;
>>> const uint32_t *y=(const uint32_t *)b;
>>>
>>> if(x[0]!=y[0]) return 0; if(x[0]==0) return 1;
>>> if(x[1]!=y[1]) return 0; if(x[1]==0) return 1;
>>> if(x[2]!=y[2]) return 0; if(x[2]==0) return 1;
>>> if(x[3]!=y[3]) return 0; if(x[3]==0) return 1;
>>> return x[4]==y[4];
>>> }
>>
>>
>
>
> with this abowe it also may be some problem as i think if i would
> write
>
> tag x = "aadadda";
>
> then im not sure if this addres of x and the adres of this "aadadda"
> constant is the same? i fact there should be not definition of type
> but adding to literals they are aligned and zero padded
>
> like
>
> (align 4, zero pad up to 20) "aadadda"
>
> and im not sure if something like that is in c here
>
>
> amd if i must create each instance of tag based on soame literal
> it would have copies by definition i think..so its not exactly what is
> needed here
>
> ai says there is an option -falign-strings=4
>
on my old version of gcc this option seem not work anyway
as i understand hovever compiler in fact is free to align string
literals to 4 and padd the to large numeber of zeros at end so
maybe sometimes he can do it and then just strcmp uses those
int comparisont to work faster..i dont know
> so eventually maybe this can be used if it is working but some would
> need to padd it with zeros too
>
> char* tag1 = "some\0\0\0\0\0\0\0"
>
>
> i dont know..it becomes to be messy sadly
>
>
>
>> still conceptually its better just to compare pointers to literals
>>
>> and this above is only a aligned and padded type of string literal
>> that is faster to strcpy..so i would need to rethink that and check how
>> convenient it is in practice
>>
>> probably for some time i will ypu with this pointer comparison
>> of normal strings and rutntime testing if it fails..then i will see
>> how much convenient it is
>
Technical Details
Message-ID:
<11afq96$2igfv$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> <11afcku$2dli3$1@dont-email.me> <11afe36$2e577$1@dont-email.me> <11afe6j$2e577$2@dont-email.me> <11afedm$2e577$3@dont-email.me> <11aff4q$2egej$1@dont-email.me> <11afiss$2fqv3$1@dont-email.me> <11afj2m$2fqv3$2@dont-email.me> <11afl3o$2giqh$1@dont-email.me> <11afls3$2gsct$1@dont-email.me> <11afoct$2hnic$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 13:00:53 +0200
Organization: A noiseless patient Spider
Lines: 80
Message-ID: <11afq96$2igfv$1@dont-email.me>
References: <11ae962$2365v$1@dont-email.me> <9tyyS.21373$VDn8.13923@fx14.ams4>
<11afcku$2dli3$1@dont-email.me> <11afe36$2e577$1@dont-email.me>
<11afe6j$2e577$2@dont-email.me> <11afedm$2e577$3@dont-email.me>
<11aff4q$2egej$1@dont-email.me> <11afiss$2fqv3$1@dont-email.me>
<11afj2m$2fqv3$2@dont-email.me> <11afl3o$2giqh$1@dont-email.me>
<11afls3$2gsct$1@dont-email.me> <11afoct$2hnic$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 11:00:55 +0000 (UTC)
Injection-Info: dont-email.me;
logging-data="2703871"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+O+iqI4m0FcL0J7Wqm/iP6NMe62c5r3oQ="; 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:uR5qZ7J3iLsl0zAM5TmNbJaIB+w= sha256:hMqtdIeWagWwSv8KRvxt4o2sBQpR/QNM6Fa7Puo3SpA=
sha1:iRK9+lkpM6ER4sVuhB4fpwyoXH4= sha256:acSes+a7sRQPIhXZVaKNM0Z+fzn1G/+5SERaQTxrn7U=
In-Reply-To: <11afoct$2hnic$1@dont-email.me>