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
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
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
ACC -S prog.C
Data Alignment and Storage
Size and Alignment of HP Compiler Data Types
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
+Wargs
+wn
+Wcontextlimit
+wperfadvice
+We
+Weargs
+Wv
Exception Handling
Extensions to the Language
+wsecurity
+noeh
Floating-Point Processing Options
+Onofenvaccess
+Onocxlimitedrange
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
+nonrv
Ipo
+Onofailsafe
Advanced +Ooptimization Options
+Onoaggressive
+Onolimit
+Onoptrstoglobals=list
+Onocrossregionaddressing
+Onodatalayout
+Onodataprefetch
+Onofltacc
+Ofrequentlycalled
+Onoinitcheck
+Olit
+Onoinline
+Ointegeroverflow
+Olevel
+Onolooptransform
+Onoloopunroll
+Onoopenmp
+opts
+Onoparminit
+Onoparmsoverlap
+Onoprocelim
+Onosignedpointers
+Orarelycalled
+Oshortdata
+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
Dname
Preprocessor Options
Redirecting Output From This Option
Maked
+Maked
+maked
Examples
Uname
Profiling Code Options
+profilebucketsize
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
+legacycpp
AOa and -AOe
+legacyv5
+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 -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
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
Unrollfactor Pragma
Stdc Fenvaccess Pragma
OMP Atomic 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 visibility
Attribute format
Attribute warnunusedresult
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
HP aC++ predefines the following predicates
Conditional Compilation #if, #ifdef, .. #endif
Code that compiles if the expression evaluates to zero
Using the defined Operator
Using the #if Directive
Using the #ifdef and #ifndef Directives
Using the #else Directive
Example
Line Control #line
#line 5 myfile
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
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
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
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
+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
Forcing the Export of Symbols in main
Advanced Shared Library Features
Updating a Shared Library
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##/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++
Using the extern C Linkage Specification
HP aC++ Calling HP C
Syntax of extern 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
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
Linking Your HP aC++ Libraries with Other Languages
Installing your Application
HP aC++ Files You May Distribute
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
More Frequent Inlining of Inline Code
Changes in C++ Syntax
Explicit int Declaration
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
Static Member Definition Required
Dangling Comma in enum
Declaring friend Classes
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
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