The code of the isgraph() function depends on the platform (or, more precisely, on the implementation). One common way is to use an initialized array of bit fields, one per character in the (single-byte) set of codes plus EOF (which must be accepted by the functions), and then select the corresponding bit. This allows a simple implementation as a macro that is safe (evaluates its argument only once) and as a simple (possibly built-in) function.
#define isgraph(x) (__charmap[(x)+1]&__PRINT)
where __charmap and __PRINT are names reserved for implementation. Part +1 deals with the general situation where EOF is -1 .
In accordance with standard C (ISO / IEC 9899: 1999):
§7.4.1.6. Graphic function
Summary
#include <ctype.h> int isgraph(int c);
Description
The check function is performed for any print character except a space ('').
and
§7.4 Character Handling <ctype.h>
¶1 The heading declares several functions useful for classifying and matching characters. 166) In all cases, the argument is an int whose value must be represented as an unsigned char or equal to the value of the EOF macro. If the argument has any other value, the behavior is undefined.
¶2 The behavior of these functions is affected by the current locale. Those functions that have locale-specific aspects only when not in the "C" locale are noted below.
¶3 The term "printable character" refers to a member of a locale-specific character set, each of which occupies a single printing position on a display device; the term control character refers to a member of a locale-specific character set that does not print characters. 167) All letters and numbers print characters.
166) See “Future Directions of the Library (7.26.2).
167) In an implementation using a seven-bit US ASCII character set, these print characters whose values range from 0x20 (space) to 0x7E (tilde); control characters are those whose values range from 0 (NUL) to 0x1F (US) and the character 0x7F (DEL).
source share