isAscii() - What for?!

If x ( isAscii(x) ) can be only char, and variable char is always ascii, what do i need this command for?

The function isAscii() is very useful to determine whether an arbitrary byte value is in the range of values defined for ASCII characters.

 x (    isAscii(x)    )

is an interesting construct... What were you trying to do ?.

ASCII is only 7 bits. Even among the ASCII characters not all are printable.

macarthur:
If x ( isAscii(x) ) can be only char, and variable char is always ascii, what do i need this command for?

'char' is not always ASCII. It's a signed 8 bit storage unit that can be used to store character codes, or for other purposes.

There is no isAscii()... there is an isascii()...

isascii is defined for all integer data types.

It is also obsolete.

isAscii() - Arduino reference

Why? Just why?

// Checks whether c is a 7-bit unsigned char value 
// that fits into the ASCII character set.
inline boolean isAscii(int c)
{
  return ( isascii (c) == 0 ? false : true);
}

When in doubt, there’s always the source.

inline boolean isAscii(int c)
{
  return ( isascii (c) == 0 ? false : true);
}

jremington:
The function isAscii() is very useful to determine whether an arbitrary byte value is in the range of values defined for ASCII characters.


Figure-1: ASCII table for the alphabets of English Language

Example-1

bool n = isAscii(0x41);
Serial.print(n, BIN);         //shows: 1 (true) which means argument of isAscii() is in Fig-1.

Example-2

bool m = isAscii(0x81);
Serial.print(m, BIN);  //shows: 0 (false) which means argument of isAscii() is beyond ASCII code

aarg:
'char' is not always ASCII. It's a signed 8 bit storage unit that can be used to store character codes, or for other purposes.

a char isn't required to always 8 bits. :wink:
There are implementations and character sets that use widths other than 8 bits for characters. (larger an smaller)
And it isn't required to be signed or unsigned. So you cannot depend on it being one or the other.

Also, char, unsigned char, and signed char, are 3 distinct types that are treated differently.
The history is long and ugly as to why this is the case.

aarg:
Why? Just why?

// Checks whether c is a 7-bit unsigned char value 

// that fits into the ASCII character set.
inline boolean isAscii(int c)
{
  return ( isascii (c) == 0 ? false : true);
}

Isn't that the Arduino way? Recreate something that already exists just because you don't like the spelling......
There is a ton of this kind of stuff in Arduino.

-- bill