In which situations is the above implementation either not sufficient or not portable?
When any EBCDIC character set is in use.
There are EBCDIC code pages where non-ASCII characters have a value between 0 and 127, for example the SPS character has value 0x09
in EBCDIC, but is not an ASCII character (it corresponds to the U+0085 Unicode code point which is encoded as 0xC2 0x85 in UTF-8, and is outside the ASCII range).
There are also ASCII characters that have a value greater than 127
in EBCDIC, such as all the alphanumeric characters! See https://en.wikipedia.org/wiki/EBCDIC#Code_page_layout which shows that all of a-z, A-Z and 0-9 are above 127. EBCDIC was always an 8-bit encoding, so the basic alnum chars did not need to be in the low 7 bits.
So for a system using EBCDIC your implementation would give isascii('\u0085')
as true
, whereas a system using UTF-8 or most other encodings that overlap with ASCII can't even represent \u0085
in a single char. More problematically, for EBCDIC your function gives isascii('a')
as false
, and isascii('0')
etc.
Live demo: https://godbolt.org/z/evK3ErErT