Subject: Re: ktr from freebsd
To: None <tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 04/30/2004 04:24:52
> Here's something that should work in any compiler.  If you try to
> invoke it with s not being a string literal, you get a syntax error.

> #define literalstrlen(s) (sizeof("" s) - 1)

<pedant>
Well, many non-string-literals.  You can invoke it with some things
that aren't in themselves valid expressions, like literalstrlen([0]),
and even some that are valid expressions, like literalstrlen(-1).  The
only thing I've been able to come up with that is both a valid to this
and valid in a "const char *" context is +0.
</pedant>

That aside, it's probably close enough for these purposes!

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B