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