🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #200

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

#200
From: fir
Date: Sun, 11 Oct 2026 10:28
68 lines
3539 bytes
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

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: <11afoct$2hnic$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-mail
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>

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 12:28:44 +0200
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <11afoct$2hnic$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Oct 2026 10:28:46 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2678348"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18ojmJMpSxASdSCxEu16XQmDB7VlTdG5pM="; 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:CVFUOVljAtSP1BHWNFljmRHXsMA= sha256:GGBfSNIBUZjwXCR+IfvSd/EeQfyBO7I5C9tY6H1siyU=
	sha1:WPalaWFIuyHCf/i4Q0GqOqsOoXQ= sha256:L7CgPUigjLAzFPN4H7CA2qW384gRHAGXSufN8jmZub4=
In-Reply-To: <11afls3$2gsct$1@dont-email.me>