Go to main content
Oracle® Developer Studio 12.5: GCC Compatibility Guide

Exit Print View

Updated: June 2017
 
 

Compiler Compatibility

This section discusses compiler features and other behavior that affect compatibility between Oracle Developer Studio and GCC.

Implementation Defined Behavior

Some parts of the C and C++ standards are left as “implementation defined behavior”. These details are defined in the GCC and Oracle Developer Studio documentation, and they differ in some ways.

Both bit-fields and enumerated types can be either signed or unsigned by the choice of the compiler. For enums, this choice can vary based on the list of enumerated values. The behavior of Oracle Developer Studio C and C++ is different from the behavior of gcc.

Signed and Unsigned int Bit-fields

Bit-fields which are declared as int (not signed int or unsigned int) can be implemented by the compiler using either signed or unsigned types. This makes a difference when extracting a value and deciding whether to sign extend it.

The Oracle Developer Studio compiler uses unsigned types for int bit-fields and the gcc compiler uses signed types. Use the gcc –funsigned-bitfields flag to control this behavior.

For more information, see the sixth list item at https://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/Non_002dbugs.html.

Signed and Unsigned enum Types

enum types in C and C++ can be implemented by the compiler using either signed or unsigned types. It can depend on the enumeration values in the specific type, so it is harder to predict. The behavior of the Oracle Developer Studio compilers is different from gcc in this regard. Oracle Developer Studio compilers use signed values for enums and gcc compilers use an unsigned type unless some the values in the enum type are explicitly assigned negative values.

Understanding the implementation differences between bit-fields declared as enum types is (so far) left as an exercise for the reader. It is best to update the source code to be more portable. For bit-fields, you can simply update the “int” declaration to be either “signed” or “unsigned” depending on how the code was written. For enum types, you can cast the type when you want to convert it to an integer and not depend on its default type.

C Language Extensions

Many C language extensions in Oracle Developer Studio are also implemented in Oracle Developer Studio C++. Some of the C extensions are documented in Extensions in Oracle Developer Studio 12.5: C User’s Guide. For the list of gcc language extensions, see Extensions to the C Language Family in the GCC documentatioin.

Some of the items listed in the gcc table are now standard features of a relevant language standard and are listed in Table 1 as C11, C99, C++03, C++11, and C++14.

Features of a newer language standard are often available as an extension when compiling according to older language standards unless either they conflict with existing code or you are using an option to enable a strict conformance mode. For more information about features that are available in different modes, see the documentation for that compiler.

The following table lists the extensions that are implemented in Oracle Developer Studio.

Table 1  GCC Extensions implemented in Oracle Developer Studio
GCC Extension
Oracle Developer Studio Implementation Status
Statement Expressions: Putting statements and declarations inside expressions.
Implemented.
Local Labels: Labels local to a block.
Implemented in C only.
Labels as Values: Getting pointers to labels, and computed gotos.
Implemented in C only.
Nested Functions: As in Algol and Pascal, lexical scoping of functions.
Not Implemented.
Constructing Calls: Dispatching a call to another function.
Not Implemented.
Typeof: referring to the type of an expression.
Implemented. New in Oracle Developer Studio 12.5 C++ C++11 defines decltype for this. In Sun (–compat=5) mode, C++ omits the typeof keyword, but still supports __typeof and __typeof__.
Conditionals: Omitting the middle operand of a ‘?:’ expression.
Implemented in C only.
__int128: 128-bit integers—__int128.
Not implemented.
Long Long: Double-word integers—long long int.
Implemented in C and C++.
Complex: Data types for complex numbers.
untyped _Complex defaults to double for compatibility with gcc. Implemented in C only.
Floating Types: Additional Floating Types.
Oracle Developer Studio C and C++ implement the 128-bit long double type, but not with the type named __float128.
Half-Precision: Half-Precision Floating Point.
Not implemented.
Decimal Float: Decimal Floating Types.
Not implemented.
Hex Floats: Hexadecimal floating-point constants.
C99. Implemented in C only.
Fixed-Point: Fixed-Point Types.
Not implemented.
Named Address Spaces: Named address spaces.
Not implemented.
Zero Length: Zero-length arrays (general zero length arrays).
int foo[0];
Implemented in C++ in GNU compatibility mode, or with –features=zla.
Zero Length: Zero-length arrays (flexible array members).
int foo[]; // at the end of a struct
Implemented in C++ in GNU compatibility mode, or with –features=zla.
Empty Structures: Structures with no members.
Implemented. For C, requires –features=extensions.
Variable Length: Arrays whose length is computed at run time.
C99. Implemented in C and C++.
Variadic Macros: Macros with a variable number of arguments
C99. Implemented in C and C++. Oracle Developer Studio implements the gcc extension for supplying a user-defined name for the variable macro arguments. gcc extensions for missing variables arguments are not implemented in C++.
Escaped Newlines: Slightly looser rules for escaped newlines.
Not implemented.
Subscripting: Any array can be subscripted, even if not an lvalue.
C99. Standard C++. Implemented in C and C++.
Pointer Arith: Arithmetic on void-pointers and function pointers.
Implemented in C only. Warning is generated.
Pointers to Arrays: Pointers to arrays with qualifiers work as expected.
Not implemented.
Initializers: Non-constant initializers.
C99. Standard C++. Implemented.
Compound Literals: Compound literals give structures, unions, or arrays as values.
C99. Implemented in C.
Designated Inits: Labeling elements of initializers.
C99. Implemented in C.
Case Ranges: `case 1 ... 9` and such.
Implemented.
Cast to Union: Casting to the union type from any member of the union.
Not implemented.
Mixed Declarations: Mixing declarations and code.
C99. Standard C++. Implemented.
Attribute Extensions
__has_attribute() can be used to test for recognized attributes. For more information, see Attributes.
Function Prototypes: Prototype declarations and old-style definitions.
Implemented in C only. Not relevant to C++.
C++ Comments: are recognized.
Implemented in C.
Dollar Signs: Dollar sign is allowed in identifiers.
Implemented. Requires –features=iddollar.
Character Escapes: ‘\e’ stands for the character <ESC>.
Not implemented.
Alignment: Inquiring about the alignment of a type or variable.
C11, spelled _Alignof. __alignof__ supported in C and C++. C++ supports alignof in C++11 mode.
Inline: Defining inline functions (as fast as macros).
C99 and Standard C++. Implemented. Before GCC implemented the standard, it created a static function body instead of an external one. If your code depends on this, you can use the C option –features=no%extinl to get similar behavior from the Oracle Developer Studio C compiler.
Volatiles: What constitutes an access to a volatile object.
Implemented. Compatible with GCC.
Using Assembly Language with C: Instructions and extensions for interfacing C with assembler.
Implemented. C and C++ implement gcc-compatible asm() statements, including constraints, asm() labels, and explicit register variables.
Alternate Keywords: __const__, __asm__, among others, for header files.
Implemented. Oracle Developer Studio 12.5 C++ added __asm and __volatile keyword spellings.
Incomplete Enums: enum foo;, with a subsequent definition.
C++11. Implemented in C and C++. Must be C++11 mode.
Function Names: Printable strings which are the name of the current function.
Oracle Developer Studio compirs support __func____FUNCTION__ and __PRETTY_FUNCTION__.
Return Address: Getting the return or frame address of a function.
Not implemented.
Vector Extensions: Using vector instructions through built-in functions.
Offsetof: Special syntax for implementing offsetof.
Not implemented.
__sync Builtins: Legacy built-in functions for atomic memory access.
Implemented. Use –xatomic=studio. See Atomics. (gcc deprecates these functions in favor of the standard __atomic builtins.)
__atomic Builtins: Atomic built-in functions with memory model.
Implemented. New in Oracle Developer Studio 12.5. Use –xatomic=studio. See Atomics.
Integer Overflow Builtins: Built-in functions to perform arithmetic and arithmetic overflow checking.
Not implemented.
x86 Specific Memory Model Extensions for Transactional Memory: x86 memory models.
Not implemented.
Object Size Checking: Built-in functions for limited buffer overflow checking.
Not implemented.
Pointer Bounds Checker Built-ins: Built-in functions for Pointer Bounds Checker.
Not implemented.
Cilk Plus Built-ins: Built-in functions for the Cilk Plus language extension.
Not implemented.
Other Builtins: Other built-in functions.
__builtin_constant_p() can test whether something is a compile-time constant. Most other built-ins are not yet implemented by Oracle Developer Studio.
Target Builtins: Built-in functions specific to particular targets.
Not implemented.
Target Format Checks: Format checks specific to particular targets.
Not implemented.
Pragmas: Pragmas accepted by gcc.
#pragma once implemented. Others not implemented.
Unnamed Fields: Unnamed struct/union fields within structs/unions.
C++11. Implemented in C and C++.
Thread-Local: Per-thread variables.
C99. C++11. Implemented in C and C++.
Binary Constants: Binary constants using the ‘0b’ prefix.
Implemented in C++ only.

SIMD Vector Support

Oracle Developer Studio supports some architecture-specific intrinsics to encode vector operations using CPU-specific instructions. The data types for these are created using the vector_size attribute or by including an appropriate header file as described in Header File Compatibility. Some C operators are supported on such types, but in some cases you might have to use the CPU-specific intrinsics.

For a discussion of types like _m128 and operations on them, see the SPARC64 X section in SIMD Intrinsics in Oracle Developer Studio 12.5: C User’s Guide.

C++ Specific Features

The Oracle Developer Studio C++ compiler supports the –features=cplusplus_redef option that enables a non-standard value of the __cplusplus macro for source codes that requires that setting.–xrestrict[=f] in Oracle Developer Studio 12.5: C++ User’s Guide

Some other GNU extensions for C++ are as follows:

  • long long constants in enumerations

  • Allowing a typedef for void as a function parameter

  • typedef void VOID;
    int foo(VOID);
  • _Bool, which is equivalent to bool on Oracle Linux when <stdbool.h> is included

  • extern template

  • long long bit-field

  • pragma pack push/pop

For information about C++ Extensions, see Extensions to the C++ Language in the GCC documentation. Information about this same functionality in the Oracle Developer Studio compiler can be found in the following table.

Table 2  GNU C++ Extensions
GNU C++ Extension
Oracle Developer Studio Implementation Status
C++ Volatiles: Determine what constitutes an access to a volatile object.
Compatible Implementation.
Restricted Pointers: C99 restricted pointers and references.
Implemented.
Vague Linkage: Where G++ puts inlines, vtables and the like.
Oracle Developer Studio also uses COMDAT for these, probably in a slightly different way.
C++ Interface: You can use a single C++ header file for both declarations and definitions.
Not implemented. Deprecated in gcc.
Template Instantiation: Methods for ensuring that exactly one copy of each needed template instantiation is emitted.
Oracle Developer Studio also uses COMDAT for these, probably in a slightly different way.
Bound member functions: You can extract a function pointer to the method denoted by a ‘->*’ or ‘.*’ expression.
Not Implemented.
C++ Attributes: Variable, function, and type attributes for C++ only.
Function Multiversioning: Declaring multiple function versions.
Not Implemented.
Namespace Association: Strong using directives for namespace association.
Not implemented. Deprecated in gcc in favor of a standard C++11 feature.
Type Traits: Compiler support for type traits.
Not Implemented.
C++ Concepts: Improved support for generic programming.
Not Implemented.
Java Exceptions: Tweaking exception handling to work with Java.
Not Implemented.
Deprecated Features: Things that are scheduled to be removed from C++.
Not Implemented.
Backwards Compatibility: Compatibilities with earlier definitions of C++.
Not Implemented.

Attributes

The full documentation for attributes implemented in the Oracle Developer Studio 12.5 compilers is in Supported Attributes in Oracle Developer Studio 12.5: C User’s Guide and Supported Attributes in Oracle Developer Studio 12.5: C++ User’s Guide.

The __has_attribute() built-in can be used with both gcc and Oracle Developer Studio compilers to test for recognized attributes.

The following attributes are new in Oracle Developer Studio 12.5 C++: aligned, deprecated, weak(alias), weakref, packed, tls_model, vector_size, and visibility.

The Oracle Developer Studio compilers do not support all of the syntaxes for attributes.

Table 3  GCC Attributes
GCC Attribute Category
Attributes supported in Oracle Developer Studio
Function Attributes: Declaring that functions have no side effects, or that they can never return.
alias, aligned, always_inline, const, constructor / destructor, deprecated (C++14), malloc, noinline, noreturn, nothrow (c++ only), pure, returns_twice, visibility, weak (and alias), weakref (C++)
Variable Attributes: Specifying attributes of variables.
aligned, deprecated, mode (C++), packed (partial implementation), tls_model, vector_size, weak
Type Attributes: Specifying attributes of types.
aligned, deprecated, packed, visibility
Enumerator Attributes: Specifying attributes on enumerators.
deprecated

Command-Line Options

Both the Oracle Developer Studio and the gcc compilers implement traditional compiler options like –g, –c, –o, and many others. The following table describes the options in the Oracle Developer Studio compilers that have been implemented specifically to be compatible with gcc.

The following options in Oracle Developer Studio are compatible with gcc.

Table 4  Compatible Options
Option
Description
–std
The –std option selects a language standard like C11, C++11, and others.
–pedantic
Issues errors or warnings for technical violations of the standard that would otherwise be accepted. This option is new in the Oracle Developer Studio 12.5 C++ compiler.
–m32 / –m64
Selects 32-bit or 64-bit binary output.
–shared
Produce a shared library. In Oracle Solaris Studio 12.4, the –shared option acted like an alias for –G. In Oracle Developer Studio 12.5, this option acts like the –shared option in gcc. See Table 5.

The following options work differently between Oracle Developer Studio and GCC.

Table 5  Options with Differences
Oracle Developer Studio Option
GCC Option
Description
–xM
–M
Print make-style dependencies for a source file. In gcc, –xM performs another function. In Oracle Developer Studio, –M selects a linker map file.
–B(static| dynamic)
–Wl,–B(static| dynamic)
GNU Linker supports this behavior, but gcc does not. Use –Wl to pass the option to GNU ld. In gcc, –B performs another function.
–G
–shared
When producing a shared library, –shared in gcc adds C++ library dependencies. The –G option in the Oracle Developer Studio compilers does not add them.

The following gcc-style options are automatically translated into corresponding options in Oracle Developer Studio. This list of options can be seen by passing this option to the following option to the C or C++ compiler: –xhelp=gccflags.

Table 6  Automatically Translated Options
gcc option in Oracle Developer Studio
Behavior in Oracle Developer Studio compilers
–MM
Same as –xM1
–Ofast
Same as –fast
–Wall
Same as +w2 (C++ only)
–Wall
Same as –v (C only)
–Werror
Same as –errwarn=%all
–Wpedantic
Same as –pedantic
–fno-elimininate-unused-debug-types
Accept and ignore
–fopenmp
Same as –xopenmp
–fPIC
Same as –KPIC
–fpic
Same as –Kpic
–fplan9-extensions
Accept and ignore (C only).
–fplugin-arg-name=t
Warn and ignore (C only)
–fplugin=t
Warn and ignore (C only)
–fsigned-char
Same as –xchar=signed (C only)
–fsyntax-only
Same as –xe
–funsigned-char
Same as –xchar=unsigned (C only)
–gdwarf-version
Same as –xdebugformat=dwarf
–gstabs
Same as –xdebugformat=stabs
–gstabs+
Suggest using –xdebugformat=stabs; option ignored
–iplugindir=t
Warn and ignore
–march=a
Same as –xtarget=a
–mcpu=a
Same as –xtarget=a
–mfmaf
Same as –fma=fused
–mno-vis
Same as –xvis=no
–mno-vis2
Same as –xvis=no
–mno-vis3
Same as –xvis=no
–mtune=a
Same as –xtarget=a
–mvis
Same as –xvis
–mvis2
Same as –xvis
–mvis3
Same as –xvis
–no-canonical-prefixes
Accept and ignore
–no-fma
Same as –fma=none
–no-fmaf
Same as –fma=none
–no-trigraphs
Same as –xtrigraphs=no
–nodefaultlibs
Same as –xnolib (C++ only)
–pass-exit-codes
Warn and ignore
–pedantic-errors
Same as –pedantic
–pipe
Warn and ignore
–save-temps
Same as –keeptmp
–shared
Same as –G
–specs=t
Warn and ignore
–traditional
Same as –Xs (C only)
–trigraphs
Same as –xtrigraphs=yes