JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.2: C++ User's Guide
search filter icon
search icon

Document Information

Preface

Part I C++ Compiler

1.  The C++ Compiler

2.  Using the C++ Compiler

2.1 Getting Started

2.2 Invoking the Compiler

2.2.1 Command Syntax

2.2.2 File Name Conventions

2.2.3 Using Multiple Source Files

2.3 Compiling With Different Compiler Versions

2.4 Compiling and Linking

2.4.1 Compile-Link Sequence

2.4.2 Separate Compiling and Linking

2.4.3 Consistent Compiling and Linking

2.4.4 Compiling for 64-Bit Memory Model

2.4.5 Compiler Command-Line Diagnostics

2.4.6 Understanding the Compiler Organization

2.5 Preprocessing Directives and Names

2.5.1 Pragmas

2.5.2 Macros With a Variable Number of Arguments

2.5.3 Predefined Names

2.5.4 Warnings and Errors

2.6 Memory Requirements

2.6.1 Swap Space Size

2.6.2 Increasing Swap Space

2.6.3 Control of Virtual Memory

2.6.4 Memory Requirements

2.7 Using the strip Command with C++ Objects

2.8 Simplifying Commands

2.8.1 Using Aliases Within the C Shell

2.8.2 Using CCFLAGS to Specify Compile Options

2.8.3 Using make

2.8.3.1 Using CCFLAGS Within make

3.  Using the C++ Compiler Options

Part II Writing C++ Programs

4.  Language Extensions

5.  Program Organization

6.  Creating and Using Templates

7.  Compiling Templates

8.  Exception Handling

9.  Improving Program Performance

10.  Building Multithreaded Programs

Part III Libraries

11.  Using Libraries

12.  Using The C++ Standard Library

13.  Using the Classic iostream Library

14.  Using the Complex Arithmetic Library

15.  Building Libraries

Part IV Appendixes

A.  C++ Compiler Options

B.  Pragmas

Glossary

Index

2.5 Preprocessing Directives and Names

This section discusses information about preprocessing directives that is specific to the C++ compiler.

2.5.1 Pragmas

The preprocessor directive pragma is part of the C++ standard but the form, content, and meaning of pragmas is different for every compiler. See Appendix B, Pragmas for details on the pragmas that the C++ compiler recognizes.

Solaris Studio C++ also supports the C99 keyword _Pragma. The followoing two invocations are equivalent:

#pragma dumpmacros(defs)     
_Pragma("dumpmacros(defs)") 

To use _Pragma instead of #pragma, write the pragma text as a literal string enclosed in parentheses as the one argument of the _Pragma keyword.

2.5.2 Macros With a Variable Number of Arguments

The C++ compiler accepts #define preprocessor directives of the following form.

#define identifier (...) replacement_list
#define identifier (identifier_list, ...) replacement_list

If the macro parameter list ends with an ellipsis, an invocation of the macro is allowed to have more arguments than there are macro parameters. The additional arguments are collected into a single string, including commas, that can be referenced by the name __VA_ARGS__ in the macro replacement list. The following example demonstrates how to use a variable-argument-list macro.

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define showlist(...) puts(#__VA_ARGS__)
#define report(test, ...) ((test)?puts(#test):\
                        printf(__VA_ARGS__))
debug(“Flag”);
debug(“X = %d\n”,x);
showlist(The first, second, and third items.);
report(x>y, “x is %d but y is %d”, x, y);

which results in the following:

fprintf(stderr, “Flag”);
fprintf(stderr, “X = %d\n”, x);
puts(“The first, second, and third items.”);
((x>y)?puts(“x>y”):printf(“x is %d but y is %d”, x, y));

2.5.3 Predefined Names

A.2.8 -Dname[=def] in the appendix shows the predefined macros. You can use these values in such preprocessor conditionals as #ifdef.The +p option prevents the automatic definition of the sun, unix, sparc, and i386 predefined macros.

2.5.4 Warnings and Errors

The #error and #warning preprocessor directives can be used to generate compile-time diagnostics.

#error token-string
Issue error diagnostic token-string and terminate compilation
#warning token-string

Issue warning diagnostic token-string and continue compilation.