strcmp for empty string

You’re right: since calling strcmp() adds up the stack management and the memory jump to the actual strcmp instructions, you’ll gain a few instructions by just checking the first byte of your string. For your curiosity, you can check the strcmp() code here: http://sourceware.org/git/?p=glibc.git;a=blob;f=string/strcmp.c;h=bd53c05c6e21130b091bd75c3fc93872dd71fe4b;hb=HEAD (I thought the code would be filled with #ifdef and obscure … Read more

Inconsistent strcmp() return value when passing strings as pointers or as literals

TL:DR: Use gcc -fno-builtin-strcmp so strcmp() isn’t treated as equivalent to __builtin_strcmp(). With optimization disabled, GCC will only be able to do constant-propagation within a single statement, not across statements. The actual library version subtracts the differing character; the compile-time eval probably normalizes the result to 1 / 0 / -1, which isn’t required or … Read more

Is the strcasecmp algorithm flawed?

The behavior is correct. Per the POSIX str\[n\]casecmp() specification: When the LC_CTYPE category of the locale being used is from the POSIX locale, these functions shall behave as if the strings had been converted to lowercase and then a byte comparison performed. Otherwise, the results are unspecified. That is also part of the NOTES section … Read more

Why is strcmp not SIMD optimized?

In a SSE2 implementation, how should the compiler make sure that no memory accesses happen over the end of the string? It has to know the length first and this requires scanning the string for the terminating zero byte. If you scan for the length of the string you have already accomplished most of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)