Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site brl-vgr.ARPA Path: utzoo!watmath!clyde!akgua!sdcsvax!sdcrdcf!hplabs!hao!seismo!brl-tgr!brl-vgr!gwyn From: gwyn@brl-vgr.ARPA (Doug Gwyn ) Newsgroups: net.unix,net.lang.c Subject: Re: Does C depend on ASCII? Message-ID: <1410@brl-vgr.ARPA> Date: Sat, 12-May-84 00:28:17 EDT Article-I.D.: brl-vgr.1410 Posted: Sat May 12 00:28:17 1984 Date-Received: Wed, 9-May-84 03:25:36 EDT References: <1873@utcsstat.UUCP> Organization: Ballistics Research Lab Lines: 27 Xref: 665 446 Traditionally C has used the host computer "native" character set (how can a convention be "native"? you ask; yet it really is). However many programs written in C implicitly assume that the character set is ASCII, although the language doesn't guarantee this. I seem to recall that the C Language Standards Committee addressed this question but I don't remember whether they decided that ASCII is the "official" C character set. For my own use in those few cases where the character codes are important, I have the following lines in my standard header file: /* integer (or character) arguments and value: */ /* THESE PARTICULAR DEFINITIONS ARE FOR ASCII HOSTS ONLY */ #define tohostc( c ) (c) /* map ASCII to host char set */ #define tonumber( c ) ((c) - '0') /* convt digit char to number */ #define todigit( n ) ((n) + '0') /* convt digit number to char */ The idea is to use toascii() to map the native input characters to internal ASCII form, although you then have to do the same to the C character constants against which the mapped input characters are to be compared (or else use numerical ASCII codes). Then on output one uses tohostc() to map the internal form back to native chars. Obviously there is non-negligible run-time overhead if the host character set is not ASCII but something stupid like EBCDIC, but I am willing to live with this in order to not have to change my source code when I port it to a non-ASCII machine (just the standard header needs to be changed).