3. Using the C++ Compiler Options
4.3 Overriding With Less Restrictive Virtual Functions
4.4 Making Forward Declarations of enum Types and Variables
4.5 Using Incomplete enum Types
4.6 Using an enum Name as a Scope Qualifier
4.7 Using Anonymous struct Declarations
4.8 Passing the Address of an Anonymous Class Instance
4.9 Declaring a Static Namespace-Scope Function as a Class Friend
4.10 Using the Predefined __func__ Symbol for Function Name
6. Creating and Using Templates
9. Improving Program Performance
10. Building Multithreaded Programs
12. Using The C++ Standard Library
13. Using the Classic iostream Library
Use the following declaration specifiers to help constrain declarations and definitions of extern symbols. The scoping restraints you specify for a static archive or an object file will not take effect until the file is linked into a shared library or an executable. Despite this, the compiler can still perform some optimization given the presence of the linker scoping specifiers.
By using these specifiers, you no longer need to use mapfiles for linker scoping. You can also control the default setting for variable scoping by specifying -xldscope on the command line.
For more information, see A.2.136 -xldscope={v}.
Table 4-1 Linker Scoping Declaration Specifiers
A symbol definition may be redeclared with a more restrictive specifier, but may not be redeclared with a less restrictive specifier. A symbol may not be declared with a different specifier once the symbol has been defined.
__global is the least restrictive scoping, __symbolic is more restrictive, and __hidden is the most restrictive scoping.
All virtual functions must be visible to all compilation units that include the class definition because the declaration of virtual functions affects the construction and interpretation of virtual tables.
You can apply the linker scoping specifiers to struct, class, and union declarations and definitions because C++ classes may require generation of implicit information, such as virtual tables and run-time type information. The specifier, in this case, follows the struct, class, or union keyword. Such an application implies the same linker scoping for all its implicit members.
For compatibility with similar scoping features in Microsoft Visual C++ (MSVC++) for dynamic libraries, the following syntax is also supported:
|
When taking advantage of this syntax with Solaris Studio C++, you should add the option -xldscope=hidden to CC command lines. The result will be comparable to the results using MSVC++. With MSVC++, __declspec(dllimport) is supposed to be used only on declarations of external symbols, not on definitions. Example:
__declspec(dllimport) int foo(); // OK __declspec(dllimport) int bar() { ... } // not OK
MSVC++ is lax about allowing dllimport on definitions, and the results using Solaris Studio C++ will be different. In particular, using dllimport on a definition using Solaris Studio C++ results in the symbol having global linkage instead of symbolic linkage. Dynamic libraries on Microsoft Windows do not support global linkage of symbols. If you run into this problem, you can change the source code to use dllexport instead of dllimport on definitions. You will then get the same results with MSVC++ and Solaris Studio C++.