From: Marc Maybe there could be a page warning about the common portability issues between g++ and sunCC (with links to the places where these are already documented). For instance: - overloading on linkage (which may disappear on linux when studio adopts the g++ mangling) - mangling issue with const/non-const or typedef - with stlport4 on solaris, the c* headers put functions in the std:: namespace only - no integer overload of the math functions - for locale support, use some other stl - a list of common g++ extensions like pretty-print, typeof, __attribute, asm and their sunCC alternatives when they exist
- todo
- overloading on linkage (G++ is currently non-compliant in this area; Sun Studio is one of the few compilers which recognizes linkage as part of the type of a function/function pointer. The correct rules are not widely understood.)
- on solaris, c* headers put functions in std:: namespace only
- no integer overload of the math functions
- story on common g++ extensions
- pretty-print
- typeof (on the way)
- __attribute (some are done)
- asm (on the way)
std:: namespace
The C standard library header files on Linux do not meet
to requirements of C++ standard. They do not put functions
into the std:: namespace. That violates the 'Annex C.2'
of C++ standard.
RW STL Gotchas
By default the Sun compiler uses the Rogue Wave implementation
of the STL. It has some issues when compared to g++.
- No member templates
- No iterator_traits
- Non-standard std::distance (sic)
- Non-standard std::count (sic)
- locale support with MT programs has problems with Sun STL.
stlport4 STL Gotchas
- stlport4 only supports C locale.
Mangling problems with typedef
See also here for mangling issues:
http://developers.sun.com/sunstudio/documentation/ss11/mr/READMEs/c++.html#cNameMangling
Mangling with const/non-const
See also here for mangling issues:
http://developers.sun.com/sunstudio/documentation/ss11/mr/READMEs/c++.html#cNameMangling
Sun C++ ABI has a bug related to const qualifier for function argument. Look at example below. Function <tt>foo</tt> defined with <tt>int</tt> argument but declared with <tt>const int</tt> argument. This code is compiled fine by g++ but Sun C++ shows an error.
% cat foo.cc
void foo(int)
{
}
% cat main.cc
void foo(const int);
int main()
{
foo(0);
}
% CC foo.cc main.cc
foo.cc:
main.cc:
Undefined first referenced
symbol in file
void foo(const int) main.o
ld: fatal: Symbol referencing errors. No output written to a.out
There are a few other name mangling bugs, most of which result in errors about undefined symbols, but you may also end up in rare cases with multiply defined symbols as well.
Unfortunately this bug cannot be fixed completely because that would break binary compatibility. Fortunately this bug has been fixed where binary compatibility is not an issue. You will only confront with this problem on solaris sparc (both 32 and 64 bits) and solaris x86, but not on solaris x64 and not on any linux. The upcoming g++ ABI compatibility mode (try <tt>-compat=g</tt> for a preview if you don't need the standard library) also fixes this.
The undocumented option <tt>-Qoption ccfe -abiopt=mangle6</tt> forces the compiler to use the new mangling scheme, but obviously it may create incompatibilities with code compiled with the regular name mangling so it should not be used in most cases.
Boost compatibility
See also: Boost and Sun Studio