12

According to the isascii() manpage:

http://linux.die.net/man/3/isascii

POSIX.1-2008 marks isascii() as obsolete, noting that it cannot be used portably in a localized application.

I'm not sure I see where the portability problem is. A very simple implementation of this function is:

int isascii(int ch) { return ch >= 0 && ch < 128; }

In which situations is the above implementation either not sufficient or not portable?

Thank you

Matthew Fioravante
  • 1,478
  • 15
  • 19
  • @SaiyamDoshi: does this do anything different? – Thilo Sep 25 '14 at 05:28
  • 1
    Whether that implementation is sufficient and portable depends on what you want to use this function for. What do you have in mind? –  Sep 25 '14 at 05:55
  • 4
    The function is definitely not portable to systems not using ASCII encoding for characters, like IBM mainframes. – Bo Persson Sep 25 '14 at 15:53

2 Answers2

5

I suppose it would not work if you have a character encoding that does not use the low seven-bit range exclusively for ASCII. Probably happens in some multibyte encodings, when the given byte is only part of the character.

For example, in Shift-JIS, the second byte can start at 0x40, which overlaps with ASCII. And even in the first byte, there are some slight alterations, such as 0x5C (currency symbol instead of backslash) or 0x7E (some sort of slash instead of tilde).

I found this article where someone explained the reason behind the non-inclusion of POSIX functions in their own OS design:

This function is rather pointless. If we use a character encoding that wasn't ascii compatible, then it doesn't make sense. If we use a sane character encoding such as UTF-8, then you can simply check if the value is at most 127.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • i think he's asking for specific encoding in which it would be true, and i can't think of any. the encodings that i know of overlap the initial 128 values. – thang Sep 25 '14 at 05:22
0

The meeting minutes have this to say:

isascii: mark obsolete. Application Usage should note that this cannot be used portably in a localized application.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173