Exporting source code to other sites

This section deals with the exporting of code from one Latin-1 coded character set to another; that is, writing code that can be run in a locale that uses a different coded character set than the one used to write the source.

To export code, use the iconv() utility to convert each source file, header file, and data file to the target coded character set. You can then send all files to the target location for compilation.
Note: You must ensure that your code runs in the same locale that it was compiled under before running it with any other locales.
  1. Use the #pragma filetag directive to tag each source file, header file, and data file.
  2. Use message files for all external strings, such as prompts, help screens, and error messages. To write truly portable code, convert these strings to the runtime coded character set in your application code.
  3. Use the setlocale() function so that the library functions are sensitive to the runtime coded character set.

    Ensure that locale-sensitive information, such as decimal points, are displayed appropriately. Use either nl_langinfo() or localeconv() to obtain this information.

    The setlocale() function does not change the CEE callable services under the z/OS® Language Environment® in such areas as date, time, currency, and time zones. Internationalization is specific to z/OS XL C/C++ applications. Also, the z/OS Language Environment CEE callable services do not change the z/OS XL C/C++ locales. For a list of these callable services, see the z/OS Language Environment Programming Guide.

  4. Compile with the locale specifying coded character set IBM-1047.

If you specify locale("locale-name"), your code will run correctly with libraries running in the same coded character set. However, if you compile with a different locale than you run under, you have to ensure that your code has no internal data, and also that all libraries you use are runtime locale sensitive.

For example, consider the following code fragment. If you compile with locale("De_DE.IBM-273"), the square brackets are converted to the hex values X'63' and X'FC'. If the default locale you then run under is not "De_DE.IBM-273", but instead "En_US.IBM-1047", and you have not used setlocale(), the square brackets will be interpreted as Ä and Ü, and the call to scanf() will not do what you intended.

int main() {
  setlocale(LC_ALL, "");
  ⋮
  rc = scanf("%[1234567890abcdefABCDEF]", hexNum);
  ⋮
}

If you only need to run your code locally or export it to a site that has your locale environment, you can solve this problem by using the following coding. This ensures that your code runs with the same locale it was compiled under. Library functions such as printf(), scanf(), strfmon(), and regcomp() are sensitive to the current coded character set. The __LOCALE__ macro is described in Using predefined macros.

int main() {
  setlocale(LC_ALL, __LOCALE__);
  ⋮
  rc = scanf("%[1234567890abcdefABCDEF]", hexNum);
  ⋮
}

If you are generating code to export to a site that may not have your locale environment, you should write your code in IBM-1047.