Determining if a C-style string is alphabetic I'm looking for the fastest way to determine if a C-style string contains only alphabetic characters.

For this question, there are a few assumptions:


strlen(c) &gt; 0
Strings are null-terminated
Continuous character encoding from a-z and A-Z is not guaranteed, but likely.
The string is not a null pointer, nor is the pointer its "default value".


#include &lt;stdbool.h&gt;
#include &lt;ctype.h&gt;

bool stralpha(const char *c)
{
    bool alphabetic = true;

    while(*c)
        alphabetic &amp;= !!isalpha(*c++);

    return alphabetic;
}

/* so gcc does not complain */
int main(void){}


To be clear: I know that any performance difference in such a function will be minimal at best. This is just for fun.

In my case, I was having issues with the function returning false even when c was purely alphabetic. That is why I use double negation !! on isalpha(), because it is not guaranteed to return consistently 0 or 1 per the standard.
The main problem with your code (in terms of performance) is that it processes every character in the string regardless. It's probably better to actually exit early if you find a non-alpha character, with something like:

bool isStrAlpha (const char *chPtr) {
    // if (*chPtr == '\0') return false;
    while (*chPtr != '\0')
        if (! isalpha (*chPtr++))
            return false;
    return true;
}


And just a couple of extra notes:


This code works fine even for zero-length strings, assuming the intent is to ensure whatever characters are in the string are all alpha. In other words, it considers an empty string valid because it contains no non-alpha characters. If you want to ensure the string has to have at least one alpha, just reinstate the commented-out line at the start of the function.
Your second assumption is superfluous. A series of characters that are not terminated with \0 is not actually a string in C.
Whether alpha characters are likely to be consecutive is not relevant in my opinion, I usually prefer correct, portable code over speed. But, in any case, you can be reasonably certain that the people who created your implementation will have optimised the wazoo out of the character classification stuff.