On Fri, May 08, 2026 at 07:47:15AM -0400, Derek Martin wrote:
> On Fri, May 08, 2026 at 08:08:13AM +0200, Rene Kita wrote:
> > strspn is one of those function I can't get into my head, that's why I
> > always end with a loop. :-) I should really try to remember it.
> 
> I prefer the loop:  They're functionally equivalent, nearly as
> succinct, and far more explicit.  you're not the only one who has
> trouble remembering it.  In professional production code I've seen
> loops far more often than strspn.  Its name doesn't really lend to one
> remembering what it does, like a lot of the less-commonly-used C
> library functions.  =8^)

FWIW, it's also very slightly more efficient.  strspn will loop over
the string, exactly as the while loop does, but a) it adds the
overhead of the function call, and b) then after the call returns you
have to do the pointer math to get where you want to go.  The while
loop solution has neither cost.

-- 
Derek D. Martin    http://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.

Reply via email to