From: Jeff King Date: Thu, 02 Nov 2006 06:51:27 GMT Subject: Re: weird strncmp usage? Message-ID: <20061102065127.GA23105@coredump.intra.peff.net> 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).