HP aC++/HP C A.06.28 Programmers Guide
Page
 Contents
 +FP
 Contents
 Contents
 Contents
 Pragma Directives and Attributes
Initialization and Termination Pragmas
Copyright Notice and Identification Pragmas
Data Alignment Pragmas
 Contents
 Preprocessing Directives 119
 Using HP aC++ Templates 132
Standardizing Your Code 138
 Optimizing HP aC++ Programs 156
Exception Handling 161
 Tools and Libraries 175
170
 Mixing C++ with Other Languages 188
 Strings 194 Arrays Files in Fortran
Distributing Your C++ Products 195
Migrating from HP C++ cfront to HP aC++ 198
 Documentation feedback 221 Diagnostic Messages 222
Glossary 223 Index 227
 HP secure development lifecycle
 What’s in This Document
About This Document
Intended Audience
 Typographical Conventions
This document uses the following conventions
 Publishing History
Related Documents
HP-UX Release Name and Release Identifier
HP-UX 11i Releases
 HP Encourages Your Comments
Following is a list of documents available with this release
 Getting Started with HP aC++
Components of the Compilation System
C89 C99 ecom Ctcom
Other HP aC++ executable files are
 Using the aCC Command
Compiling a Simple Program
Executing the Program
Debugging Programs
 Compiler Command Syntax and Environmental Variables
Examples of the aCC Command
 Files on the aCC Command Line
Assembly Language Source Files .s Files
++ Source File .C file
Preprocessed Source Files .i Files
 Configuration Files .conf Files
Environment Variables
Object Files .o Files
Library Files .a and .so Files
 ACCFULLPATHNAMES Environment Variable
ACCMAXERR Environment Variable
Cxxopts Environment Variable
Cclibdir Environment Variable
 Ccrootdir Environment Variable
ACC -L/mnt/proj/lib file.o ACC file.o
 Floating Installation
Cxxmapfile Environment Variable
Tmpdir Environment Variable
Export CCROOTDIR=/mnt/CXX2.1
 Setting up Floating Installation
HP aC++
 Command-Line Options
 Options to Control Code Generation
ACC -c sub.C prog.C
ACC +DO11.22 +O3 app.C
ILP32 Data Model and LP64 Data Model
 Using +DS to Specify Instruction Scheduling
Compiling in Networked Environments
 Size and Alignment of HP Compiler Data Types
Data Alignment and Storage
ACC -S prog.C
 Debugging Options
Fshort-enums
+expandtypesindiag
ACC +u1 app.C
 When to use -g, -g0, and -g1
Differences Between -g, -g0, and -g1 Options
G1 Algorithm
+macrodebug
 +noobjdebug
+pathtrace
+pathtrace=kind
Local
 Error Handling
None
+pathtrace=globallocal
ACC +p file.C
 +Wcontextlimit
+wn
+Wargs
 +wperfadvice
+We
+Weargs
+Wv
 Exception Handling
Extensions to the Language
+wsecurity
+noeh
 +Onocxlimitedrange
+Onofenvaccess
Floating-Point Processing Options
 Fpeval
Fpevaldec
Nofpwidetypes
+decfp
 +FPmode
+Onolibmerrno
+Oprefetchlatency
+Onopreservedfpregs
 Header File Options
 ACC -I include file.C Idirs -I- -Idirs
 Online Help Option
+help
 Inlining Options
+inlinelevel num
 Library Options
Dynamic
Exec
Lname
 Linker Options
Minshared
+nostl
+Onolibcalls=
 Usymbol
Usymbol
+Onodynopt
+Onodynopt
 Options for Naming the Output File
Native Language Support Option
+ild
+ildrelink
 Handling Null Pointers Options
Code Optimizing Options
Basic Optimization Level Options
ACC -z file.C
 +O0
+O1
+O2
+O3
 Additional Optimization Options for Finer Control
+O4
ACC +O3 prog.C
+O4
 +Onofailsafe
Ipo
+nonrv
 Advanced +Ooptimization Options
+Onoaggressive
+Onolimit
+Onoptrstoglobals=list
 +Onocrossregionaddressing
+Onodatalayout
+Onodataprefetch
+Onofltacc
 +Ofrequentlycalled
+Onoinitcheck
 +Ointegeroverflow
+Onoinline
+Olit
 +Olevel
+Onolooptransform
+Onoloopunroll
+Onoopenmp
 +opts
+Onoparminit
+Onoparmsoverlap
+Onoprocelim
 +Oshortdata
+Orarelycalled
+Onosignedpointers
 +Otypesafety
Profile-Based Optimization Options
+Onostoreordering
+Ounrollfactor
 Parallel Processing Options
Information Embedding Options
Displaying Optimization Information
Annotate=structs
 Option Matrix for -mt
Required if -DPOSIXCSOURCEis used
 +Onoautopar
+tls=staticdynamic
 Performance Options
+wlock
Fast
+Ofast
 +Ofaster
+Onotlscallschangetp
+nosrcpos
+DSmodel
 Porting Options
+sb
+ub
+uc
 +w64bit
+wdriver
+wendian
This warning can be suppressed by adding an extra cast
 Redirecting Output From This Option
Preprocessor Options
Dname
 Maked
+Maked
+maked
Examples
 +profilebucketsize
Profiling Code Options
Uname
 Runtime Checking Options
+check
+check=all
+check=none
 +check=boundsarray +check=boundspointer
Compiling with +check=boundspointer
 Check off by one out-of-bounds access
Check off by any number out-of-bounds access
 +check=globals
+check=lock
 +check=malloc
 +check=stackframevariablesnone
+check=thread
 +check=truncateexplicitimplicit
+check=uninit
Ch = intval & 0xff +check=truncateexplicit
+check=truncateimplicit
 Aarm
Standards Related Options
Aarm
 AC89
AC99
Ag++
Agcc
 +legacyv5
AOa and -AOe
+legacycpp
 +std=c89c99c++98c++11gccg++gnu
+stl=rwnone
 +tru64
Wc,-ansiforscope,onoff
Wc,-koeniglookup,onoff
+tru64
 Subprocesses of the Compiler
Tx,name
More Examples of -t
Tx,name
 Wx,args
 Symbol Binding Options
Bdefault
Bextern
Passing Options to the Linker with -W
 Bhidden
Bhiddendef
Bprotected
Bprotecteddata
 Template Options
 Trigraph Processing Suppression Option
+instincludesuffixes
 Verbose Compile and Link Information
 Process Compiler 94/u 65/s 35/r 37/u 76/s 02/r
 ACC myfile.C -v -g1 ACC myfile.C -vg1 ACC -vg1 myfile.C
Concatenating Options
ACC -V app.C
 Pragma Directives and Attributes
Initialization and Termination Pragmas
 Copyright Notice and Identification Pragmas
 Data Alignment Pragmas
#pragma Versionid string
#pragma Versionid Software Product, Version 12345.A.01.05
#pragma align N
 Data Alignment Pragmas
 Basic Example
Template Example
 Implicit Access to Unaligned Data
Handling Unaligned Data
 #pragma unalign Typedef T1 T2
Interaction between pack and unalign pragmas is as follows
 Optimization Pragmas
Optlevel Pragma
Optimize Pragma
Floattrapson Pragma
 Noinline Pragma
 Diagnostic Pragmas
Other Pragmas
 Defaultbinding Pragma
Binding Pragma
Estimatedfrequency Pragma
Extern Pragma
 Hdrstop Pragma
Hidden Pragma
Hpdefinedexternal Pragma
Hpdefinedinternal Pragma
 POP Pragma
Pragma once
Protected Pragma
Ptrsstronglytyped Pragma
 #pragma Stdc FLOATCONSTDECIMAL64 on OFF Default
Stdc Cxlimitedrange Pragma
Stdc FLOATCONSTDECIMAL64 Pragma
Stdc Fpcontract Pragma
 OMP Atomic Pragma
Stdc Fenvaccess Pragma
Unrollfactor Pragma
 OMP Barrier Pragma
OMP Critical Pragma
OMP for Pragma
OMP Flush Pragma
 OMP Master Pragma
OMP Ordered Pragma
OMP Parallel Pragma
OMP Parallel for Pragma
 OMP Parallel Sections Pragma
OMP Sections Pragma
OMP Single Pragma
OMP Task Pragma
 OpenMP Clauses
 Default
Copyprivate
Shared
Copyin
 Attributes
 Attribute nonexposing
Attribute noreturn
Attribute nonexposing
Attribute noreturn
 Attribute warnunusedresult
Attribute format
Attribute visibility
 Preprocessing Directives
Overview of the Preprocessor
Syntax
Usage Guidelines
 Source File Inclusion #include, #includenext
Syntax
Description
Assertions #assert, #unassert
 Macro Replacement #define, #undef
#define mac very very long\ Replacement string
Examples
Macros with Parameters
 Specifying String Literals with the # Operator
Concatenating Tokens with the ## Operator
Example
Following illustrates the ## operator
 Using Macros to Define Constants
Other Macros
Var1 is
#define Arraysize 1000float xARRAYSIZE
 Using Constants and Inline Functions Instead of Macros
 Assertions #assert, #unassert
Predefined Macros
 Code that compiles if the expression evaluates to zero
Conditional Compilation #if, #ifdef, .. #endif
HP aC++ predefines the following predicates
 Using the defined Operator
Using the #if Directive
Using the #ifdef and #ifndef Directives
Using the #else Directive
 #line 5 myfile
Line Control #line
Example
 This macro enables the following non-standard features
Iostream Performance Improvement Pragma
Pragma Directive #pragma and Pragma Operator
See page 96 for more information on pragmas
 Error Directive #error
Trigraph Sequences
Examples
Line below contains the trigraph sequence ??=
 When this line is compiled it becomes
??=line 5 myfile
 Using HP aC++ Templates
Invoking Compile-Time Instantiation
Scope and Precedence
Template Processing
 Explicit Instantiation
Usage
Performance
Template class Tablechar
 Command-Line Option Instantiation
Compile-Time Instantiation
Function Template
ACC -c +instcompiletime a.C ACC -c a.C
 Why Use Compile-Time Instantiation
Possible Duplicate Symbols in Shared Libraries
Possible Duplicate Symbols in Archive Libraries
Scope
 ++ Template Tutorial
Class Templates
Building an Archive Library with +instauto/+instclose
Building an Archive Library with Compile-time Instantiation
 Function Templates
 Standardizing Your Code
HP aC++ Keywords
Bool Keyword
HP aC++ Keywords
 Compile time error message is
Dynamiccast Keyword
 Above generates a compile-time error
 Explicit Keyword
 Classic example of this problem is an array class
 Mutable Keyword
 Namespace and using Keywords
Connections Across Translation Units
 Using- declarations and using- directives
Using Nx // Where N is a namespace, x is a name in N
An Auxiliary Translation Unit
Int
Page
 Class Base Virtual void f Must have a virtual function to
 Volatile Keyword
 Typename Keyword
Wchart Keyword
Template Keyword
 Declare a class as a member of the class template C2 below
Overloading new and delete for Arrays
Use it as the name of the template C below
 Example
 Invalidargument
Rangeerror
Standard Exception Classes
 Following exceptions are thrown by the Standard C++ Library
Exceptions Thrown by the Standard C++ Library
Typeinfo Class
 Unsupported Functionality
Int before const typeinfo& const
 Memfun1reft Memfunreft Iostream
 Setting Basic Optimization Levels
Optimizing HP aC++ Programs
Requesting Optimization
Level 1 Optimization
 Additional Options for Finer Control
Level 3 Optimization
Level 4 Optimization
Enabling Aggressive Optimizations
 Removing Compilation Time Limits When Optimizing
Profile-Based Optimization
Enabling Only Conservative Optimizations
Limiting the Size of Optimized Code
 Instrumentation
Collecting Data for Profiling
Maintaining Profile Data Files
Sample.exe input.file1 Sample.exe input.file2
 Pragmas That Control Optimization
Performing Profile-Based Optimization
ACC -o sample.exe +Oprofile=use +O3 sample.C
See Optimization Pragmas page 103 for more information
 Exception Handling
Exception Handling in C++
 Basic Exception Handling Example
Function Try Block Examples
 Using Threads
Using Locks
Debugging Exception Handling Performance Considerations
Rogue Wave Standard C++ Library
 Required Command-line Options
Rogue Wave Standard C++ Library
Rogue Wave Standard C++ Library 1.2.1 and Tools.h++
LpthreadThis option applies only to kernel threads
 Using -DTHREADSAFE with the cfront Compatible libstream
Using -DHPACCTHREADSAFERBTREE
Limitations
Cout endl
 ACC -mt prog.c
Pthreads Posix Threads
Exception Handling
 OpenMP Implementation
Parallel Programming Using OpenMP
Function Scoping
 OpenMP APIs are defined in the library libomp
OpenMP Header File
OpenMP Library
 +Onoopenmp Command Line Option
Environment Variables in OpenMP
Openmp Macro
Where, kind is either of of static, dynamic, or guided
 Runtime Library Functions in OpenMP
Execution Environment Functions
Export OMPDYNAMIC=value Setenv Ompdynamic value
Export OMPNESTED=value Setenv Ompnested value
 Ompsetnumthreads
Ompgetnumthreads
Ompgetmaxthreads
Ompgetthreadnum
 Lock Functions
Ompsetdynamic
Ompgetdynamic
Ompsetnested
 Ompinitlock and ompinitnestlock
Ompdestroylock and ompdestroynestlock
Ompsetlock and ompsetnestlock
Ompunsetlock and ompunsetnestlock
 Timing Functions
Omptestlock and omptestnestlock Functions
Ompgetwtime
Ompgetwtick
 HP Specific Features of lex and yacc
Creating and Using Libraries
Tools and Libraries
Locale directive for lex
 Introduction to Using the Standard C++ Library
HP aC++ Libraries
Standard C++ Library
Introduction
 Differences between Standard C++ Library and Other Libraries
Non-Object-Oriented Design of the Standard C++ Library
 Standard C++ Library Reference
Incompatibilities Between the Library and the Standard
 ACC -DHPACCUSINGMULTIPLIESINFUNCTIONAL test.c
Tools.h++ Library
HP aC++ Runtime Support Library
IOStream Library
 Creating and Using Shared Libraries
Linking to C++ Libraries
Linking with Shared or Archive Libraries
Specifying Other Libraries
 Using a Shared Library
Example of Creating and Using a Shared Library
Creating a Shared Library
Linking Archive or Shared Libraries
 Updating a Shared Library
Advanced Shared Library Features
Forcing the Export of Symbols in main
 Binding Times
Side Effects of C++ Shared Libraries
Routines and Options to Manage C++ Shared Libraries
Linker Options to Manage Shared Libraries
 Standard HP-UX Libraries and Header Files
Allocation Policies for Containers
 For -AA Standard Library
For a string type
 HP aC++ File Locations
HP aC++ Executable Files
 Usr/lib/hpux##/libCsup11.so ISO C++11 standard compliant
HP aC++ Runtime Libraries and Header Files
Usr/lib/hpux##/libCsup.so
 Data Compatibility between C and C++
Mixing C++ with Other Languages
Calling Other Languages
 Using the extern C Linkage Specification
HP aC++ Calling HP C
Syntax of extern C
Examples of extern C
 Examples HP aC++ Calling HP C
Differences in Argument Passing Conventions
Main Function
 Enter the nameJoann Joann has a balance
HP C Calling HP aC++
Running the Example
 To compile the example, run the following commands
Compiling and Running the Sample Programs
 Using Reference Variables to Pass Arguments
Calling HP Fortran 90 from HP aC++
Function Naming Conventions
Example of Reference Variables as Arguments
 Using extern C Linkage
Strings
Arrays
Files in Fortran
 Distributing Your C++ Products
Applications that use HP aC++ Shared Libraries
 HP aC++ Files You May Distribute
Installing your Application
Linking Your HP aC++ Libraries with Other Languages
 Terms for Distribution of HP aC++ Files
 Migrating from HP C++ cfront to HP aC++
General Guidelines for Migration
Getting Started with Migration
CC +p cfrontfile.C
 Command-Line Differences
New Command-Line Options
Writing Code for both Compilers
Explicit Loading and Unloading of Shared Libraries
 Obsolete Command-Line Options
Describes obsolete command-line options for HP aC++
 Changed Command-Line Options
Ptv
 Migration Considerations when Debugging
Migration Considerations when Using Exception Handling
Exception Handling is the Default
See Debugging Options page 35 for complete information
 Possible Differences when Exiting a Signal Handler
Memory Allocation Failure and operator new
 Differences in setjmp/longjmp Behavior
Calling unexpected
 Unreachable catch Clauses
Throwing an Object having an Ambiguous Base Class
 Migration Considerations when Using Libraries
Standards Based Libraries
 HP C++ cfront Compatibility Libraries
Fstream3C++ iostream and streambuf specialized to files
Manip3C++ iostream manipulators
Man 3s filebuf
 Migration Considerations Related to Preprocessing
HP C++ cfront Complex Library Not Supported
HP C++ cfront Task Library Not Supported
Replace #include with complex
 Migration Considerations Related to Standardization
Obsolete Preprocessor Options
Changes in C++ Semantics
Implicit Typing of Character String Literals
 Overload Resolution Ambiguity of Subscripting Operator
Execution Order of Static Constructors in Shared Libraries
 Explicit int Declaration
Changes in C++ Syntax
More Frequent Inlining of Inline Code
 For Statement, New Scoping Rules
Struct as Template Type Parameter is Permitted
Equivalent, valid HP aC++ code follows
WC,-ansiforscope,on
 This code compiles without error with HP aC++
Base Template Class Reference Syntax Change
Tokens after #endif
Overload not a Keyword
 Declaring friend Classes
Dangling Comma in enum
Static Member Definition Required
 Using in Class Definitions
Incorrect Syntax for Calls to operator new
Duplicate Formal Argument Names
Ambiguous Function or Object Declaration
 Overloaded Operations ++
Reference Initialization
 Using operator new to Allocate Arrays
On HP aC++, the following error is generated
Compiling this code HP aC++ generates the following error
Parentheses in Static Member Initialization List
 Qualified-id Required in Static Member Initialization List
Non-constant Reference Initialization
 Migration Considerations when Using Templates
Verbose Template Processing Information
Digraph White Space Separators
CA a
 Cfront Implicit Include Convention
Converting Directed Mode to Explicit Instantiation
Common Template Migration Syntax Changes
 Documentation feedback
 Frequently Encountered Messages
Diagnostic Messages
AC++ Message Catalog
 Glossary
Aggressive
 International Standard defines only synchronous exceptions
 See template
 Glossary
 Symbols
Index
 Crootdir
 FLOATTRAPSON, 103 FREQUENTLYCALLED, 106 HDRSTOP, 107 Hidden
 Index