From: Jeff King <peff@peff.net>
To: Andy Whitcroft <apw@shadowen.org>
Cc: hanwen@xs4all.nl, git@vger.kernel.org
Subject: Re: weird strncmp usage?
Date: Thu, 2 Nov 2006 01:51:27 -0500 [thread overview]
Message-ID: <20061102065127.GA23105@coredump.intra.peff.net> (raw)
In-Reply-To: <45494D84.2060402@shadowen.org>
On Thu, Nov 02, 2006 at 01:44:36AM +0000, Andy Whitcroft wrote:
> That said if you know its constant you can also use sizeof("foo") and
> that is done at compile time. Something like:
>
> #define strxcmp(x, y) strncmp((x), (y), sizeof((y))
You would, of course, need to use sizeof(y)-1 to avoid comparing the NUL
termination. :)
This is a slightly dangerous macro, because it _only_ works for string
literals, but not pointers (which is fine in this case, but its
limitations need to be documented).
next prev parent reply other threads:[~2006-11-02 6:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-02 1:26 weird strncmp usage? Han-Wen Nienhuys
2006-11-02 1:44 ` Andy Whitcroft
2006-11-02 6:51 ` Jeff King [this message]
2006-11-02 9:15 ` Johannes Schindelin
2006-11-02 9:59 ` Han-Wen Nienhuys
2006-11-02 11:04 ` Petr Baudis
2006-11-03 21:05 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061102065127.GA23105@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=apw@shadowen.org \
--cc=git@vger.kernel.org \
--cc=hanwen@xs4all.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).