TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Thomas Seeling
from: Tobias Ernst
date: 1999-09-30 10:49:05
subject: Letters are not assumed to be contiguous!

Hallo Thomas!

 TT>>>          c = (((c-'a')+13)%26)+'a';
 TT>> This assumes contiguous letters of course.

 TS> afair Ansi-/ISO-C forces letters and digits to be ordinally 
 TS> contiguous.

No! Digits are forced to be contiguous, but letters are not. That is why
ctype.h provides macros like toupper and tolower, and isalpha. Compilers for
ASCII platforms may well implement those macros in the way above, but the
programmer should never do it.

The reason is obvious: All existing charsets have contiguous digits, but not
all of them have contiguous digits. For example EBCDIC (used in S/390 and
AS/400) does not have contiguous letters. EBCDIC has 0..F (hex digits 0..9,
a..f) contiguos, but the other letters were added at a later time and
therefore follow at another position.

And: OS/390 uses EBCDIC, and does not only have an ISO-certified C compiler,
but, when using the Open Edition, it even has all POSIX certificates to allow
itself to be called "Unix". 

Thinking about it, implementing toupper like upper = (lower -'a') + 'A' might
even work in EBCDIC, because the displacemenet between f and g is the same as
that between F and G, but implementing isalpha like  

  (c >= 'a' && c = 'A' && c <= 'Z')

certainly would not work on EBCDIC. This is a major issue in porting spaghetti 
code applications like R/3  to OS/390.

Viele Grüße,
Tobias

--- Msged/BSD TE 06 (pre)
102
2320/38
* Origin: Running FreeBSD 3.2 (2:2476/418)

SOURCE: echoes via The OS/2 BBS

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.