Usage example
The design point for ASCII/EBCDIC Mixed Mode support for Enhanced ASCII was to make it possible for C++ class library and DLL developers to develop a common mixed mode version of their library instead of producing separate ASCII and EBCDIC versions. The class library or DLL developer can accomplish this by calling explicit ASCII and EBCDIC versions of C-RTL functions based on the results of a call to __isASCII(). __isASCII() is used to determine the character mode of the user application. It is assumed that the end user application is not bimodal. A simple ASCII/EBCDIC bimodal "Hello World!" program shows how a bimodal class library or DLL can be produced. For this example, it is assumed that the user application (the code containing main()) is compiled ASCII while the bimodal code, which is contained in a separate compile unit, is compiled EBCDIC.
#include <stdio.h>
void printItOut(const char *, const char *);
void main(void) {
printItOut("%s\n", "Hello World!");
}
Assuming the preceding code was compiled using the ASCII compile option, the C/C++ Compiler will generate values for the characters in the format string and the "Hello World!\n" string in the ISO8859-1 code page. A separate compile unit contains the bimodal printItOut() function, as shown below:
#define _AE_BIMODAL 1
#include <stdio.h>
#include <_Nascii.h>
void printItOut(const char *format, const char *string {
if (__isASCII())
__printf_a(format, string);
else
__printf_e(format, string);
}
In the example, the format and string arguments passed on the call to printItOut will be in the ISO8859-1 code page. __isASCII() returns the character mode of the current thread. In this example, the character mode of the initial processing thread is ASCII. This was set during C-RTL initialization since the compile unit containing main() was compiled ASCII.
hellow 2 >&1 | iconv -f ISO8859-1 -t IBM-1047