Compiler notes for handling of pointers
- The xlc compiler provides limited support for 16-byte alignment (for type long double) by using the combination of -qlngdbl128 and -qalign=natural. Type ILEpointer requires these compiler options to ensure that machine interface (MI) pointers are 16-byte aligned within structures. Using option -qldbl128 forces type long double to be a 128-bit type that requires use of libc128.a to handle operations like printf for long double fields.
An easy way to get option -qlngdbl128 and link with libc128.a is to use the xlc128 command instead of thexlc command.
- The xlc/xlC compiler currently does not provide a way to force 16-byte alignment for static or automatic variables. The compiler only guarantees relative alignment for 128-bit long double fields within structures. ThePASE for i version of malloc always provides 16-byte aligned storage, and you can arrange 16-byte alignment of stack storage.
- Header file as400_types.h also relies on type long long to be a 64-bit integer. xlc compiler option -qlonglong ensures this geometry (which is not the default for all commands that run the xlc compiler).
Examples
The following examples are intended for use when you are compiling your PASE for i programs on an AIX system. If you are using a compiler installed in PASE for i to compile your programs, you do not need to specify compiler options for the locations of IBM i system-unique header files or IBM i system-unique exports because these files will be found in their default path locations of /usr/include/ and /usr/lib/ on an IBM i system.
Example 1
The following command on an AIX system creates an PASE for i program named testpgm that can use IBM i system-unique interfaces exported by libc.a:
xlc -o testpgm -qldbl128 -qlonglong -qalign=natural
-bI:/mydir/as400_libc.exp testpgm.c
This example assumes that the IBM i system-unique header files are copied to the AIX directory /usr/include and that the IBM i system-unique exports files are copied to the AIX directory /mydir.
Example 2
The following example assumes IBM i system-unique headers and export files are in /pase/lib:
xlc -o as400_test -qldbl128 -qlonglong -qalign=natural -H16
-l c128
-I /pase/lib
-bI:/pase/lib/as400_libc.exp as400_test.c
Example 3
The following example builds the same program as example 2 with the same options; however, the xlc_r command is used for a multithreaded program to ensure that the compiled application links with threadsafe runtime libraries:
xlc_r -o as400_test -qldbl128 -qlonglong -qalign=natural -H16
-l c128
-I /pase/lib
-bI:/pase/lib/as400_libc.exp as400_test.c
In the examples, if you are using PASE for i support for IBM Db2® for i call level interfaces (CLIs), you also need to specify -bI:/pase/include/libdb400.exp on your build command.
The -bI directive tells the compiler to pass the parameter to the ld command. The directive specifies an export file containing exported symbols from a library to be imported by the application.