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 __GNUSOMETHING, but it's actually rather simple!)

Answer from Gui13 on Stack Overflow
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Odd results for strcmp / strncmp for empty string - Programming - Arduino Forum
March 5, 2021 - strcmp and strncmp returns are <0 the first character that does not match has a lower value in str1 than in str2 0 the contents of both strings are equal 0 the first character that does not match has a greater value …
🌐
PHP
php.net › manual › en › function.strcmp.php
PHP: strcmp - Manual
2) The resulting strings are compared with two possible outcomes: a) if one of the resulting strings is an empty string, then the length of the non-empty string is returned (the sign depending on the order in which you pass the arguments to ...
🌐
Reddit
reddit.com › r/explainlikeimfive › eli5: why does strcmp crash when you compare it against a null?
r/explainlikeimfive on Reddit: ELI5: Why does strcmp crash when you compare it against a null?
August 14, 2018 - A null string means no string at all, whereas an empty string is a string, just one with a length of 0. ... Most of the time it's going to be a memory address pointing to a single null-terminator ( \0 ), essentially telling the computer "Your ...
🌐
C For Dummies
c-for-dummies.com › blog
Null Versus Empty Strings | C For Dummies Blog
Array empty[] at Line 6 is created as an empty string. It has a single element, a null character. The length of this string is zero, though it has one element. Array null[] at Line 7 is a null string. It’s declared, allocated 5 elements, but never assigned any values.
🌐
Quora
quora.com › Does-STRCMP-check-for-NULL
Does STRCMP check for NULL? - Quora
Answer: int strcmp (const char* str1, const char* str2); * strcmp() function takes two strings and returns an integer. * strcmp() compares two strings character by character. * If the first character of two strings is equal, the next character of two strings are compared. This continues until...
Find elsewhere
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 74027-how-test-if-string-empty.html
How to test if a string is empty
Oh I see, I didn't think about the fact that a string is an array and that if it's empty the first value would read '\0'.... Thanks again cwr, you've been a great help. ... I also notice you're using improper string comparisons in your program. In that last if statement you'd want to use strcmp() ...
🌐
Quora
quora.com › What-happens-when-a-non-empty-string-is-compared-with-an-empty-string
What happens when a non empty string is compared with an empty string? - Quora
Answer (1 of 5): Usually length is first compared (pascal-alike structure that you will find in many high-level modern-languages and implementations), so no string is compared to another, length will tell that they are different, and even that the non-empty might be superior to the empty one. On...
🌐
IBM
ibm.com › docs › en › i › 7.4.0
strcmp() — Compare Strings
We cannot provide a description for this page right now
🌐
SA-MP Forum
sampforum.blast.hk › showthread.php
strcmp + empty string = FAIL
Ok im working on some kinda map system and sometimes i gave a empty strings so when i use strcmp and i compare empty string with something strcmp return me 0 (strings are same) WTF? I also tried to add length but still same bug...anyone can confirm these?
🌐
Onebite
onebite.dev › snippet › c › check-if-a-string-is-empty-in-c
check if a string is empty in C - Code Snippets with explanation
January 11, 2023 - In this code, strcmp() is used to compare the string given to the empty string (""). If the two strings are equal, the strcmp() function will return a value of 0. Therefore, if the value of strcmp(string,"") is 0, that means the string is empty.
🌐
Cppreference
en.cppreference.com › w › c › string › byte › strcmp
strcmp - cppreference.com
"follows" : "equals"; printf("[%s] %s [%s]\n", lhs, rel, rhs); } int main(void) { const char* string = "Hello World!"; demo(string, "Hello!"); demo(string, "Hello"); demo(string, "Hello there"); demo("Hello, everybody!" + 12, "Hello, somebody!" + 11); } Output: [Hello World!] precedes [Hello!] [Hello World!] follows [Hello] [Hello World!] precedes [Hello there] [body!] equals [body!] C23 standard (ISO/IEC 9899:2024): 7.24.4.2 The strcmp function (p: TBD) C17 standard (ISO/IEC 9899:2018): 7.24.4.2 The strcmp function (p: TBD) C11 standard (ISO/IEC 9899:2011): 7.24.4.2 The strcmp function (p: 365-366) C99 standard (ISO/IEC 9899:1999): 7.21.4.2 The strcmp function (p: 328-329) C89/C90 standard (ISO/IEC 9899:1990): 4.11.4.2 The strcmp function ·
🌐
Cppreference
en.cppreference.com › w › cpp › string › byte › strcmp.html
std::strcmp - cppreference.com
The behavior is undefined if lhs or rhs are not pointers to null-terminated strings. Negative value if lhs appears before rhs in lexicographical order. Zero if lhs and rhs compare equal. Positive value if lhs appears after rhs in lexicographical order. ... #include <algorithm> #include <cstring> #include <iostream> #include <vector> int main() { std::vector<const char*> cats{"Heathcliff", "Snagglepuss", "Hobbes", "Garfield"}; std::sort(cats.begin(), cats.end(), [](const char* strA, const char* strB) { return std::strcmp(strA, strB) < 0; }); for (const char* cat : cats) std::cout << cat << '\n'; }
🌐
Itecnote
itecnote.com › tecnote › r-strcmp-for-empty-string
Strcmp for empty string
Skip to content · React-native – React Native Error: “Animated.event now requires a second argument for options” · Python – keep on getting “x and y must have same first dimension, but have shapes (100,) and (1, 100)” · Java – Docker WARNING: Published ports are discarded when ...