Appendix B. The IBM C++ Language Extensions

To maintain compatibility as a superset of C, IBM C++ implements features for compatibility at the C99 language level and with GNU C language extensions. In addition, IBM C++ supports a subset of the GNU extensions to C++. Like the IBM C language extensions, the C++ extensions have both orthogonal and non-orthogonal language features. An orthogonal extension is a feature that is added on top of a base without altering the behavior of the existing language features. A non-orthogonal extension is one that can change the semantics of existing constructs or can introduce syntax conflicting with the base.

This appendix presents the IBM C++ language extensions by category. The compiler option syntax for enabling and disabling an individual language feature is the same as for IBM C. All language extensions orthogonal to Standard C++ or C++98 are collectively enabled by compiling in the extended mode. Enabling a particular feature redundantly does not change its enabled state.

The compiler options are documented in detail in XL C/C++ Compiler Reference.


Orthogonal Extensions

The orthogonal IBM C++ extensions fall into three subgroupings: those that are related to C99 features to maintain compatibility with C, those related to GNU C, and those related to GNU C++.

IBM C++ Extensions for Compatibility with C99

IBM C++ adds the following C99 language features.

The IBM C++ extensions for compatibility with IBM C at the C99 language level
Language Feature Remarks
The restrict type qualifier Defines a restricted pointer or reference.
Variable length arrays
Flexible array members C99 allows a flexible array member only at the end of a struct. GNU C allows it anywhere in the structure.
Support for the complex data type
Support for hexadecimal floating-point constants
Universal character names C++ code point range expanded to match that of C99
Compound literals
vararg macros Function-like macros with variable arguments
Trailing comma allowed in enum declaration
Empty macro arguments
Additional predefined macro names
_Pragma preprocessing operator
__func__ predefined identifier
UTF-16, UTF-32 literals

IBM C++ Extensions Related to GNU C


The orthogonal IBM C++ language extensions related to GNU C
Language Extension Compiler Option and Remarks
Statements and Declarations in Expressions -qlanglvl=extended
Locally Declared Labels -qlanglvl=gnu_locallabel
Labels as Values -qlanglvl=gnu_labelvalue
Computed goto -qlanglvl=gnu_computedgoto
Referring to a Type with typeof -qkeyword=__typeof__
GNU C Complex Types -qlanglvl=c99complex, -qlanglvl=gnu_complex
GNU C Hexadecimal Float Constants -qlanglvl=c99hexfloat
Array of Length Zero -qlanglvl=compatzea
Arrays of Variable Length -qlanglvl=c99vla
Macros with Variable Number of Arguments -qlanglvl=varargsmacros, -qlanglvl=gnu_varargmacros
Using an identifier in place of __VA_ARGS__.
Compound Literals -qlanglvl=c99compoundliteral
Attributes for functions, variables, and types -qkeyword=__attribute__
Grouped together because all use the keyword __attribute__.
__alignof__ to inquire about the alignment -qkeyword=__alignof__
Assembler Instructions with C Expression Operands -qasm=gcc, -qkeyword=asm
Variables in specified registers -qlanglvl=gnu_explicitregvar
When the suboption is specified, the compiler accepts the GNU syntax but ignores the semantics.
Alternate Keywords -qkeyword=inline -qkeyword=const -qkeyword=volatile -qkeyword=signed -qkeyword=__alignof__ -qkeyword=__asm__ -qkeyword=__inline__ -qkeyword=__const__ -qkeyword=__extension__ -qkeyword=__restrict__ -qkeyword=__signed__ -qkeyword=__typeof__ -qkeyword=__volatile__
These options have been created for problematical keywords.
#assert, #unassert, #cpu, #machine, #system -qlanglvl=gnu_assert
Grouped together because all operate on assertions.
#warning -qlanglvl=gnu_warning
#include_next -qlanglvl=gnu_include_next

IBM C++ Extensions Related to GNU C++


The orthogonal IBM C++ language extensions related to GNU C++
Language Extension Compiler Option and Remarks
Variable Attribute init_priority -qlanglvl=__attribute__
Locally Declared Labels Supported only when declared in a block.

Non-Orthogonal Extensions

The non-orthogonal IBM C++ extensions fall into two subgroupings: those that are related to C99 features and those related to GNU C.

IBM C++ Extensions for Compatibility with C99


The non-orthogonal IBM C++ language extensions for compatibility with IBM C at the extended C99 language level
Language Extension Remarks
The inline keyword Non-orthogonal to Standard C++, C++98, C89, and GNU C.
Flexible array members C99 allows a flexible array member only at the end of a struct. GNU C allows it anywhere in the structure. C++ provides partial support by allowing zero-extent arrays.

IBM C++ Extensions Related to GNU C


The non-orthogonal IBM C++ language extensions related to GNU C
Language Extension Compiler Option and Remarks
typeof -qkeyword=typeof
Non-orthogonal because typeof is under the user namespace.
Macros with a Variable Number of Arguments -qlanglvl=varargsmacros
Removal of trailing comma when no variable macro arguments are specified.

IBM Copyright 2003