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