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
Distributing Your C++ Products 195
Migrating from HP C++ cfront to HP aC++ 198
Strings 194 Arrays Files in Fortran
Documentation feedback 221 Diagnostic Messages 222
Glossary 223 Index 227
HP secure development lifecycle
About This Document
Intended Audience
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
Data Alignment and Storage
ACC -S prog.C
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
+wn
+Wargs
+Wcontextlimit
+Weargs
+wperfadvice
+We
+Wv
+wsecurity
Exception Handling
Extensions to the Language
+noeh
+Onofenvaccess
Floating-Point Processing Options
+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
Ipo
+nonrv
+Onofailsafe
+Onolimit
Advanced +Ooptimization Options
+Onoaggressive
+Onoptrstoglobals=list
+Onodataprefetch
+Onocrossregionaddressing
+Onodatalayout
+Onofltacc
+Ofrequentlycalled
+Onoinitcheck
+Onoinline
+Olit
+Ointegeroverflow
+Onoloopunroll
+Olevel
+Onolooptransform
+Onoopenmp
+Onoparmsoverlap
+opts
+Onoparminit
+Onoprocelim
+Orarelycalled
+Onosignedpointers
+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
Preprocessor Options
Dname
Redirecting Output From This Option
+maked
Maked
+Maked
Examples
Profiling Code Options
Uname
+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
Standards Related Options
Aarm
Aarm
Ag++
AC89
AC99
Agcc
AOa and -AOe
+legacycpp
+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
Concatenating Options
ACC -V app.C
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
Stdc Fenvaccess Pragma
Unrollfactor 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 format
Attribute visibility
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
Conditional Compilation #if, #ifdef, .. #endif
HP aC++ predefines the following predicates
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
Line Control #line
Example
#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
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
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
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
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
Advanced Shared Library Features
Forcing the Export of Symbols in main
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
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++
Syntax of extern C
Using the extern C Linkage Specification
HP aC++ Calling HP C
Examples 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
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
Installing your Application
Linking Your HP aC++ Libraries with Other Languages
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
Changes in C++ Syntax
More Frequent Inlining of Inline Code
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
Dangling Comma in enum
Static Member Definition Required
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
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
Glossary
Aggressive
International Standard defines only synchronous exceptions
See template
Glossary
Symbols
Index
Crootdir
FLOATTRAPSON, 103 FREQUENTLYCALLED, 106 HDRSTOP, 107 Hidden
Index