Re: String comparison for fixed strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Glynn Clements wrote:

> 1. The test against the NUL byte can't be eliminated unless you know
> in advance that the string is long enough.

Actually, this is false. If the variable string terminates
prematurely, it will differ from the fixed string at that point, so a
separate NUL check is unnecessary.

As Jesse points out, the logical alternative to the hard-coded
comparisons is memcmp(), not strcmp().

You only need to use strcmp() if you don't know the length of either
string in advance.

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux