Features related to GNU C and C++ portability

To facilitate porting an application or code developed with GNU C, XL C/C++ supports a subset of the GNU C and C++ language extensions to C99 and Standard C++. The tables in this section list the features that are supported, unsupported, and those for which the syntax is accepted but the semantics ignored.

To use supported extensions with your C code, use the xlc or cc invocation commands, or specify one of -qlanglvl=extc89, -qlanglvl=extc99, or -qlanglvl=extended. In C++, all supported GNU C and C++ features are accepted by default.

In the following tables, extensions marked accept/ignore are recognized by the compiler as acceptable programming keywords, but the GNU C/C++ semantics are not supported. This means that compilation does not halt if the compiler encounters an accept/ignore keyword or extension, but the GNU semantics are not implemented in the application. Compiling source code that uses these extensions under a strict language level (stdc89, stdc99) will result in error messages.

Related References

The GNU C and C++ language extensions are fully documented in the GNU manuals at http://gcc.gnu.org/onlinedocs.

Function attributes

Use the keyword __attribute__ to specify special attributes when making a function declaration or definition. This keyword is followed by an attribute specification inside double parentheses. XL C/C++ supports a subset of the GNU C and C++ function attributes. Behavior described as accept/ignore means that the syntax is accepted, but the semantics are ignored, and compilation continues.

GNU C/C++ function attribute compatibility with XL C/C++
Function Attribute Behavior
alias supported
always_inline supported
cdecl accept/ignore
const supported
constructor supported
destructor supported
dllexport accept/ignore
dllimport accept/ignore
eightbit_data accept/ignore
exception accept/ignore
format supported
format_arg supported
function_vector accept/ignore
interrupt accept/ignore
interrupt_handler accept/ignore
longcall accept/ignore
model accept/ignore
no_check_memory_usage accept/ignore
no_instrument_function accept/ignore
noinline supported
noreturn supported
pure supported
regparm accept/ignore
section supported
stdcall accept/ignore
tiny_data accept/ignore
weak supported

Related References

Variable attributes

Use the keyword __attribute__ to specify special attributes of variables or structure fields. This keyword is followed by an attribute specification inside double parentheses. XL C/C++ supports a subset of the GNU C and C++ variable attributes. Behavior described as accept/ignore means that the syntax is accepted, but the semantics are ignored, and compilation continues.

GNU C/C++ variable attribute compatibility with XL C/C++
Variable Attribute Behavior
aligned supported
C++ Onlyinit_priority
supported
mode supported
model accept/ignore
nocommon supported
packed supported
section supported
transparent_union supported
unused accept/ignore
weak supported

Related References

Type attributes

Use the keyword __attribute__ to specify special attributes of struct and union types when you define these types. This keyword is followed by an attribute specification inside double parentheses. XL C/C++ supports a subset of the GNU C and C++ type attributes. Behavior described as accept/ignore means that the syntax is accepted, but the semantics are ignored, and compilation continues.

GNU C/C++ type attribute compatibility with XL C/C++
Type Attribute Behavior
aligned supported
packed supported
transparent_union supported
unused accept/ignore

Related References

GNU C and C++ assertions

Use assertions to test what sort of computer or system the compiled program will run on. The assertions #cpu, #machine, and #system are predefined. You can also define assertions with the preprocessing directives #assert and #unassert.

GNU C and C++ assertions in XL C/C++
GNU C Assertions Behavior
#assert supported
#unassert supported
#cpu supported
possible value is powerpc
#machine supported
possible values are powerpc and bigendian
#system supported
possible values are unix and posix

Other GNU C and C++ portability issues

The following features related to GNU C and C++ are supported under extended language levels (extc89, extc99, extended).

Under extended language levels (extc89, extc99, extended), XL C/C++ recognizes the syntax of the following features, but their semantics are not supported.

Related References

Standard C++ Numerics Library header files

It should be noted that not all of the math functions in the XL C++ header files <cmath> and <cstdlib> can handle an argument of integral type. The reason is that the conversion of an argument from an integral type to a floating-point type creates multiple overload resolution possibilities of equal rank.

For example, taking the absolute value of an unsigned int or an unsigned long in a C++ program results in an overload resolution error, despite the fact that the XL C++ implements all of the required signatures for the abs() library function in its headers.

int abs(int);
long abs(long);
float abs(float);
double abs(double);
long double abs(long double);

The problem persists even if both of the XL headers <math.h> and <stdlib.h> are included. The workaround is to cast an argument of unsigned integral type to a suitable type before using it in the function. IBM Copyright 2003