🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #198

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

#198
From: fir
Date: Sun, 11 Oct 2026 09:45
32 lines
2643 bytes
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];
> }


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: <11afls3$2gsct$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>

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 11:45:38 +0200
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <11afls3$2gsct$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Oct 2026 09:45:40 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2650525"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+pGWCKCTHsirA3b0Sc2pLwPO4FAPfIQOE="; 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:qFElemoTdZ4JWBWufCC+QCOChBg= sha256:1DuwYFuwCxYgM1LS+w4SsU9kDMysTw8XCPWqVWpIW6U=
	sha1:LM93lDYHqqKUhRqVMotGLDZZinE= sha256:e16VPqUuBixNcmZa0MWxNjflp07xl3Kd9Yy8L1S98Wg=
In-Reply-To: <11afl3o$2giqh$1@dont-email.me>