IBM VisualAge XL C/C++ and GNU GCC/G++ both are ISO/ANSI standard-compliant, although XL claims to provide a higher level of compliance. In most cases, however, with the exception of a few warnings, applications built with XL C/C++ compile and link with GNU GCC/G++ with minimal effort. In its simplest form, the following syntax shows the similarity in compiler invocation under IBM and GNU. Here's your typical "Hello World" source compiled and linked with both XL and GNU compilers.
As you can see, the only difference between IBM XL C/C++ and GNU GCC/G++ is the invocation method between the C and C++ compile and link stage. For applications migrating from IBM environments, the equivalent C/C++ invocation under GNU is gcc/g++, respectively.
However, some migrations are not so straightforward. There are differences. The extent of those differences depends on the type of output you are trying to build, the code being ported, how well the original developers adhered to ANSI standards, and the number of dependent environment APIs used inside the application being ported.
One of the many features that IBM tried to build into their compiler is ease of use. Long ago, they recognized that developers used the same distinct parameters to build certain applications. For instance, in AIX, to build a multithreaded application, you must include the POSIX threads system library in your executable (libpthread). The same holds true for standard AIX system calls such as streams and file manipulations; developers must include the standard system library (libc.a) or some variant thereof.
To ease the complexity of trying to remember all the different required parameters and libraries to include when invoking their compiler, IBM introduced distinct compiler invocation methods that in turn turned on certain parameters and included distinct libraries automatically depending on the desired output. For instance, to build a multithreaded C application, the developer merely would have to invoke the xlc_r compiler method. The _r denotes REENTRANT, meaning the resulting executable will be thread-safe. When invoked on the compile line, this method automatically turns the following parameters on and includes the following libraries:
GNU GCC/G++ does not provide for this type of shorthand method in building certain types of applications. Depending on your desired output, you must include the appropriate library(s) and parameter(s) on the command line. For instance, the equivalent command in Linux that will replace the IBM XL C xlc_r method is as follows:
Table 5-2 provides a GNU reference for each IBM XL C/C++ compiler invocation.
For POSIX threads, depending on the current distribution of Linux you are porting to, additional preprocessor directives may need to be turned on. Refer to the document that came with your distribution.
Both IBM and GCC provide an array of compiler switches that enable the user to control the behavior and the type of output generated. For instance, both have optimization parameters to control the size and performance characteristics of an output, as well as switches to control how the executable is built, such as L and I switches, which control the search path of libraries and include files. In addition, some switches are architecture-specific and are exclusive to either IBM XLC/C++ or GCC. Table 5-3 compares compiler switches between IBM XLC/C++ and gcc/g++. Because some of the qoption switches for IBM XLC/C++ are architecture-specific, a comparable GCC compiler switch is not available.
Table 5-3. XLC/C++ and gcc/g++ Compiler Switches Comparison Table
C/C++ VisualAge for AIX Option[10] | GNU gcc Option[11] | Description (AIX-based) |
---|
-+ | -x c++ | (C++) Compiles any file, filename.nnn, as a C++ language file, where nnn is any suffix other than .o, .a, or .s. |
-# | -### | Traces the compilation without doing anything. |
-q32 -q64 | -m32[12] -m64[12] | Selects 32- or 64-bit compiler mode. Additional m options for GCC are available. Refer to GNU Documentation Online. |
-qlanglvl=<option> | -fstd=<OPTION> | Specifies which language level to use when invoking the compiler. |
-qaggrcopy | None | Enables destructive copy operations for structures and unions. |
-qalias -qansialias | -fstrict-aliasing | Specifies which type-based aliasing is to be used during optimization. |
-qalign | -mstrict-align[12] | Specifies what aggregate alignment rules the compiler uses for file compilation. |
-qalloca -ma | None | Substitutes inline code for calls to function alloca as if #pragma alloca directives are in the source code. |
-qarch | -mcpu=cpu_type[12] | Specifies the type of IBM architecture on which the executable program will be run. This refers to all the RS6000 and POWER architectures. |
-qnoassert | None | Asks the compiler to apply aliasing assertions to your compilation unit. |
-qattr | None | Produces a compiler listing that includes an attribute listing for all identifiers. |
B, t | -B | -B: Determines substitute path names for the compiler, assembler, linkage editor, and preprocessor. -t: Adds the prefix specified by the -B option to designated programs. -tE replaces the CreateExportList script. |
-bdynamic -bshared | -shared fpic (or fPIC) -Bsharable or -Wl brt -shared | Instructs the linker to process subsequent shared objects as either dynamic or shared. |
-bstatic | -static -Bstatic -dn -non-shared | Links all referenced objects statically although they may be shared objects. |
-qbitfields | -fsigned-bitfields (default) | Specifies whether bitfields are signed. |
-bmaxdata | Refer to the section, "Large Page Support," in Chapter 3. | Sets the size of the heap in bytes. |
-brtl | -shared -wl Refer Section 5.5, "Linker." | Enables runtime linking. |
-C | -C | Preserves comments in preprocessed output. |
-c | -c | Instructs the compiler to pass source files to the compiler only. |
-qcache | None | Specifies a cache configuration for a specific execution machine. |
-qchars=[signed or unsigned] | -fsigned-char funsigned-char | Instructs the compiler to treat all variables of type char as either signed or unsigned. |
-qcheck | None | Generates code that performs certain types of runtime checking |
-qcinc | None | (C++) Includes files from specified directories have the tokens extern " C " { inserted before the file, and } appended after the file. |
-qcompact | -Os | When used with optimization, reduces code size where possible, at the expense of execution speed. |
-qcpluscmt | C++ syle of comments is turned on automatically in GNU C, unless ansi is turned on. | (C++) Use this option if you want C++ comments to be recognized in C source files. |
-D | -D | Defines the identifier name, as in a #define preprocessor directive. |
-qdataimported | None | Marks data as imported. Used to import functions. |
-qdatalocal | None | Marks data as local. |
-qdbxextra | None | (C only) Specifies that all typedef declarations, struct, union, and enum type definitions are included for debugger processing. |
-qdigraph | None | Allows use of digraph character sequences in your program. |
-qdollar | fdollars-in-identifiers This is the default behavior of GNU on most platforms. | Allows the $ symbol to be used in the names of identifiers. |
-qdpcl | None | Generates block scopes to support the IBM Dynamic Probe Class Library. |
-E | -E | Runs the source files named in the compiler invocation through the preprocessor. |
-eLabel | -e Label --entry=Label Refer to the "Linker" section. | Specifies the entry name for the shared object. Equivalent to using ld -e name. See your system documentation for additional information about ld options. Used only with qmkshrobj. |
-qeh | -fexceptions | (C++) Controls exception handling. |
-qenum | Use keyword __attribute__[13] | Specifies the amount of storage occupied by the enumerations. |
-qexpfile | None | Saves all exported symbols in a file. |
-qextchk | None | Generates bind-time type of checking information and checks for compile-time consistency. |
-F | None | Names an alternative configuration file for xlC. |
-f | None | Names a file to store a list of object files. |
-qfpdr | None | Collects program information for use with the AIX fdpr performance-tuning utility. |
-qflag | None | Specifies the minimum severity level of diagnostic messages to be reported. |
-qfloat | None (Accuracy of floating-point is different on differing platforms.) | Specifies various floating-point options to speed up or improve the accuracy of floating-point operations. |
-qflttrap | -mfp-trap-mode= TRap mode | Generates extra instructions to detect and trap floating-point exceptions. |
-qfold | None | Specifies that constant floating-point expressions are to be evaluated at compile time. |
-qfullpath | None | Specifies what path information is stored for files when you use -g and the distributed graphical debugger. |
-qfuncsect | None | Places instructions for each function in a separate object file, control section, or csect. |
-G | -shared Bshareable | Linkage editor (ld command) option only. Used to generate a dynamic libary file. |
-g | -g | Generates debugging information used by a debugger such as the Distributed Debugger. |
-qgenproto | None | Produces ANSI prototypes from K&R function definitions. |
-qhalt | None | Instructs the compiler to stop after the compilation phase when it encounters errors of specified severity or greater. |
-qhaltonmsg | None | Enables debug versions of memory management functions. |
-qhot | None | Instructs the compiler to perform high-order transformations on loops and array language during optimization, and to pad array dimensions and data objects to avoid cache misses. |
-qhsflt | None | Speeds up calculations by removing range checking on single-precision float results and on conversions from floating-point to integer. |
-qhssngl | None | Specifies that single-precision expressions are rounded only when the results are stored into float memory locations. |
-I | -I | Specifies an additional search path if the filename in the #include directive is not specified using its absolute path name. |
-qidirfirst | None | Specifies the search order for files included with the #include file_name directive. |
-qignerrno | None | Allows the compiler to perform optimizations that assume errno is not modified by system calls. |
-qignprag | None | Instructs the compiler to ignore certain pragma statements. |
-qinfo | None | Produces informational messages. |
-qinitauto | None | Initializes automatic storage to a specified two-digit hexadecimal byte value. |
-qinlglue | None | Generates fast external linkage by inlining the pointer glue code necessary to make a call to an external function or a call through a function pointer. |
-qinline | -finline-functions | Attempts to inline functions instead of generating calls to a function. |
-qipa | None | Turns on or customizes a class of optimizations known as interprocedural analysis (IPA). |
-qisolated_call | None | Specifies functions in the source file that have no side effects. |
-qkeepinlines | -fkeep-inline-function | (C++) Instructs the compiler to keep or discard definitions for unreferenced extern inline functions. |
-qkeyword | None | Controls whether a specified string is treated as a keyword or an identifier. |
-L | -L | Searches the specified directory for library files specified by the -l option. |
-l | -l | Searches a specified library for linking. |
-qlanglvl | -ansi flang-isoc9x | Selects the C or C++ language level for compilation. |
-qlargepage | Refer to the "Large Page Support," section. | Instructs the compiler to exploit large page heaps available on Power4 systems running AIX v5.1D or later. |
-qldbl128, -qlongdouble | None | Increases the size of long double type from 64 bits to 128 bits. |
-qlibansi | None | Assumes that all functions with the name of an ANSI C library function are in fact the system functions. |
-qlinedebug | None | Generates abbreviated line number and source filename information for the debugger. |
-qlist | None | Produces a compiler listing that includes an object listing. |
-qlistopt | None | Produces a compiler listing that displays all options in effect. |
-qlonglit | None | Makes unsuffixed literals the long type for 64-bit mode. |
-qlonglong | -mlong64 (Refer to the m options for your targeted platform.) | Allows long long types in your program. |
-M | -M | Creates an output file that contains targets suitable for inclusion in a description file for the AIX make command. |
-ma | Refer to alloc. | (C only) Substitutes inline code for calls to function alloca as if #pragma alloca directives are in the source code. |
-qmacpstr | None | (C only) Converts Pascal string literals into null-terminated strings where the first byte contains the length of the string. |
-qmaf | None | Specifies whether the floating-point multiply-add instructions are to be generated. |
-qmakedep | -M | Creates an output file that contains targets suitable for inclusion in a description file for the AIX make command. |
-qmaxerr | None | Instructs the compiler to halt compilation when a specified number of errors of specified or greater severity is reached. |
-qmaxmem | None | Limits the amount of memory used for local tables of specific, memory-intensive optimizations. |
-qmbcs dbcs | LANG[14] | Use the -qmbcs option if your program contains multibyte characters. |
-qmkshrobj | -shared or libtool[15] | Creates a shared object from generated object files. |
-qnamemangling | None | Selects the name-mangling scheme for external symbol names generated from C++ source code. |
-O -qoptimize | -O | Optimizes code at a choice of levels during compilation. |
-o | -o | Specifies a name or directory for the output executable file(s) created either by the compiler or the linkage editor. |
-qobjmodel | None | (C++) Sets the type of object model. |
-qoldpassbyvalue | None | (C++) Specifies how classes containing const or reference members are passed in function arguments. |
-P | -E | Preprocesses the C or C++ source files named in the compiler invocation and creates an output preprocessed source file for each input source file. |
-p | None | Sets up the object files produced by the compiler for profiling. |
-qpascal | None | (C only) Ignores the word pascal in type specifiers and function declarations. |
-qpath | None | Constructs alternate program and path names. |
-qpdf1 -qpdf2 | None | Tunes optimizations through Profile-Directed Feedback. |
-pg | -fprofile-generate | Sets up the object files for profiling, but provides more information than is provided by the -p option. |
-qphsinfo | gcov[16] | Reports the time taken in each compilation phase. |
-qprint | None | Suppresses listings. |
-qpriority | None | (C++) Specifies the priority level for the initialization of static constructors. |
-qproclocal -qprocimported -qprocunknown | None | Marks functions as local, imported, or unknown. |
-qproto | None | (C only) Assumes all functions are prototyped. |
-Q | -O3 | Attempts to inline functions instead of generating calls to a function. |
-r | -mrelocatable | Produces a relocatable object. |
-qreport | None | Instructs the compiler to produce transformation reports that show how program loops are parallelized and optimized. |
-qrndflt | None | Controls the compile-time rounding mode of constant floating-point expressions. |
-qrndsngl | None | Specifies that the result of each single-precision float operation is to be rounded to single precision. |
-qro | None | Specifies the storage type for string literals. |
-qroconst | None | Specifies the storage location for constant values. |
-qrrm | None | Prevents floating-point optimizations that are incompatible with runtime rounding to plus and minus infinity modes. |
-qrtti | None | (C++) Generates runtime type identification (RTTI) information for the typeid operator and the dynamic_cast operator. |
-S | -S | Generates an assembly language file (.s) for each source file. |
-s | None | Strips the symbol table. |
-qshowinc | None | If used with -qsource, all the include files are included in the source listing. |
-qsmallstack | None | Instructs the compiler to reduce the size of the stack frame. |
-qsmp | None | Enables parallelization of IBM SMP-compliant program code. |
-qsource | None | Produces a compiler listing and includes source code. |
-qspill | None | Specifies the size of the register allocation spill area. |
-qspnans | None | Generates extra instructions to detect signaling NaN on conversion from single precision to double precision. |
-qsrcmsg | None | (C only) Adds the corresponding source code lines to the diagnostic messages in the stderr file. |
-qstaticinline | None | (C ++) Controls whether inline functions are treated as static or extern. |
-qstatsym | None | Adds user-defined, nonexternal names that have a persistent storage class to the name list. |
-qstdinc | -nostdinc (nostdinc++ for and C++ source ) | Specifies which files are included with #include <file_name> and #include "file_name" directives. |
-qstrict | None | Turns off aggressive optimizations of the -O3 option that have the potential to alter the semantics of your program. |
-qstrict_induction | None | Disables loop-induction variable optimizations that have the potential to alter the semantics of your program. |
-qsuppress | None | Specifies compiler message numbers to be suppressed. |
-qsymtab | None | Set symbol tables for unreferenced variables or xcoff objects. |
-qsyntaxonly | -fsyntax-only | (C only) Causes the compiler to perform syntax checking without generating an object file. |
-qtabsize | None | Changes the length of tabs as perceived by the compiler. |
-qtbtable | None | Sets traceback table characteristics. |
-qtempinc | -frepo | (C++) Generates separate include files for template functions and class declarations, and places these files in a directory, which can be optionally specified. |
-qtemplaterecompile | -frepo | (C ++) Helps manage dependencies between compilation units that have been compiled using the -qtemplateregistry compiler option. |
-qtemplateregistry | -frepo | (C++) Maintains records of all templates as they are encountered in the source and ensures that only one instantiation of each template is made. |
-qtempmax | None | (C++) Specifies the maximum number of template include files to be generated by the tempinc option for each header file. |
-qthreaded | -lpthread -D_REENTRANT | Indicates that the program will run in a multithreaded environment. |
-qtmplparse | None | (C++) Controls whether parsing and semantic checking are applied to template definition implementations. |
-qtocdata | None | Marks data as local. |
-qtocmerge | None | Enables TOC merging to reduce TOC pointer loads and improves the scheduling of external loads. |
-qtune | -b | Specifies the architecture for which the executable program is optimized. |
-qtwolink | None | (C++) Minimizes the number of static constructors included from libraries. |
-U | -U | Undefines a specified identifier defined by the compiler or by the -D option. |
-qunique | None | (C++) Generates unique names for static constructor/deconstructor file-compilation units. |
-qunroll | -funroll-loops | Unrolls inner loops in the program. |
-qunwind | None | Informs the compiler that the application does not rely on any program stack unwinding mechanism. |
-qupconv | None | Preserves the unsigned specification when performing integral promotions. |
-V | None | Instructs the compiler to report information on the progress of the compilation in a command-like format. |
-v | -v | Instructs the compiler to report information on the progress of the compilation. |
-qvftable | -fvtable-thunks | (C++) Controls the generation of virtual function tables. |
-W | None | Passes the listed words to a designated compiler program. |
-w | -w | Requests that warning messages be suppressed. |
-qwarn64 | None | Enables warning of possible long to integer data truncations. |
-qxcall | None | Generates code to static routines within a compilation unit as if they were external calls. |
-qxref | None | Produces a compiler listing that includes a cross-reference listing of all identifiers. |
-y | None | Specifies the compile-time rounding mode of constant floating-point expressions. See also rndflt. |