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