🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #229

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

#229
From: MitchAlsup
Date: Sun, 11 Oct 2026 19:30
33 lines
1725 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> posted:

> 
> fir <profesor.fir@gmail.com> posted:
> -------------------
> > 
> > if("cat" == "cat") will return true and
> > if("cat" == "dog") will return false
> 
> "cat" in C means a pointer p points at {'c' 'a' 't' 00} in memory; so,
> if you want character comparison you want:
> 
>      if( strcmp( "cat", "dog" ) == 0 ) //cat = dog
> 
> And that one will never have the flow of control enter the then
> clause; whereas:
> 
>      if( strcmp( "cat", "cat" ) == 0 ) //cat = cat
> 
> and you will always enter the then clause, regardless of whether 
> the compiler uses the same literal twice or not.
> 
One can also add:

# define areEQUAL   == 0
# define areINEQUAL != 0
# define areLESS    < 0
# define areGREATER > 0

So you can write:

     if( strcmp( "cat", "dog" ) areEQUAL )
Technical Details
Message-ID: <1791747021-5857@newsgrouper.org>
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!newsgrouper.org!.POSTED!not-for-mail
References: <11ae962$2365v$1@dont-email.me> <1791743331-5857@newsgrouper.org>

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!newsgrouper.org!.POSTED!not-for-mail
From: MitchAlsup <user5857@newsgrouper.org.invalid>
Newsgroups: comp.lang.c
Subject: Re: compare literals / if( "cat"== "dog") {}
References: <11ae962$2365v$1@dont-email.me> <1791743331-5857@newsgrouper.org>
Date: Sun, 11 Oct 2026 19:30:21 GMT
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <1791747021-5857@newsgrouper.org>
Injection-Info: newsgrouper.org; mail-complaints-to="newsgrouper@yahoo.com"; posting-account=user5857
Injection-Date: Sun, 11 Oct 2026 19:30:21 GMT
User-Agent: Newsgrouper/0.9.0