HP C-aC++ User's Guide

5 (1)

HP aC++/HP C A.06.28 Programmer's Guide

Integrity servers

HP Part Number: 769150-001

Published: March 2014

Edition: 13

© Copyright 2012, 2014 Hewlett-Packard Development Company, L.P.

Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license. The information contained herein is subject to change without notice. The only warranties for HP products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty. HP shall not be liable for technical or editorial errors or omissions contained herein. UNIX is a registered trademark of The Open Group.

Intel® and Itanium® are trademarks of Intel Corporation in the U.S. and other countries.

Contents

 

HP secure development lifecycle....................................................................

17

About This Document ..................................................................................

18

Intended Audience..................................................................................................................

18

What’s in This Document.........................................................................................................

18

Typographical Conventions.................................................................................................

19

HP-UX Release Name and Release Identifier..........................................................................

20

Publishing History...................................................................................................................

20

Related Documents.................................................................................................................

20

HP Encourages Your Comments................................................................................................

21

1 Getting Started with HP aC++...................................................................

22

Components of the Compilation System.....................................................................................

22

Using the aCC Command...................................................................................................

23

Compiling a Simple Program...............................................................................................

23

Executing the Program........................................................................................................

23

Debugging Programs.........................................................................................................

23

HP Code Advisor..........................................................................................................

23

HP WDB Debugger.......................................................................................................

23

Accessing Online Example Source Files...........................................................................

24

Compiler Command Syntax and Environmental Variables.............................................................

24

Examples of the aCC Command..........................................................................................

24

Compiling and Renaming an Output File..........................................................................

24

Compiling and Debugging ............................................................................................

24

Compiling Without Linking.............................................................................................

24

Linking Object Files.......................................................................................................

24

Compiling, Optimizing, and Getting Verbose Information...................................................

24

Compiling and Creating a Shared Library........................................................................

25

Files on the aCC Command Line...............................................................................................

25

C++ Source File (.C file).....................................................................................................

25

Preprocessed Source Files (.i Files) .......................................................................................

25

Assembly Language Source Files (.s Files) .............................................................................

25

Object Files (.o Files)..........................................................................................................

26

Library Files (.a and .so Files)..............................................................................................

26

Configuration Files (.conf Files)............................................................................................

26

Environment Variables.............................................................................................................

26

aCC_FULL_PATHNAMES Environment Variable......................................................................

27

aCC_MAXERR Environment Variable....................................................................................

27

CXXOPTS Environment Variable...........................................................................................

27

CCLIBDIR Environment Variable...........................................................................................

27

CCROOTDIR Environment Variable.......................................................................................

28

CXX_MAP_FILE Environment Variable...................................................................................

29

TMPDIR Environment Variable..............................................................................................

29

Floating Installation.................................................................................................................

29

HP aC++..........................................................................................................................

30

HP C................................................................................................................................

30

Setting up Floating Installation.............................................................................................

30

2 Command-Line Options.............................................................................

31

Options to Control Code Generation.........................................................................................

32

-c ....................................................................................................................................

32

+DOosname ....................................................................................................................

32

+DDdata_model ...............................................................................................................

32

Contents 3

+DSmodel........................................................................................................................

33

Using +DS to Specify Instruction Scheduling.....................................................................

33

Compiling in Networked Environments.............................................................................

33

-S.....................................................................................................................................

33

Data Alignment and Storage....................................................................................................

34

-fshort-enums ....................................................................................................................

35

+unum .............................................................................................................................

35

Debugging Options................................................................................................................

35

+d...................................................................................................................................

35

+expand_types_in_diag.....................................................................................................

35

-g....................................................................................................................................

35

-g0..................................................................................................................................

35

-g1..................................................................................................................................

36

Differences Between -g, -g0, and -g1 Options........................................................................

36

When to use -g, -g0, and -g1..............................................................................................

36

-g, -g1 Algorithm...............................................................................................................

36

+macro_debug..................................................................................................................

36

+[no]objdebug..................................................................................................................

37

+pathtrace........................................................................................................................

37

Error Handling.......................................................................................................................

38

+p...................................................................................................................................

38

-w....................................................................................................................................

38

+w...................................................................................................................................

39

+wn.................................................................................................................................

39

+Wargs............................................................................................................................

39

+Wcontext_limit................................................................................................................

39

+We................................................................................................................................

40

+Weargs..........................................................................................................................

40

+Wv................................................................................................................................

40

+Wwargs.........................................................................................................................

40

+wlint...............................................................................................................................

40

+Wmacro.........................................................................................................................

40

+wperfadvice....................................................................................................................

40

+wsecurity........................................................................................................................

41

Exception Handling................................................................................................................

41

+noeh..............................................................................................................................

41

Extensions to the Language......................................................................................................

41

-ext..................................................................................................................................

41

+e...................................................................................................................................

42

Floating-Point Processing Options..............................................................................................

42

+O[no]cxlimitedrange........................................................................................................

42

+O[no]fenvaccess..............................................................................................................

42

-fpeval..............................................................................................................................

43

-fpevaldec.........................................................................................................................

43

-[no]fpwidetypes................................................................................................................

43

+decfp.............................................................................................................................

43

+FP..................................................................................................................................

43

+FPmode..........................................................................................................................

44

+O[no]libmerrno...............................................................................................................

44

+Oprefetch_latency............................................................................................................

44

+O[no]preserved_fpregs.....................................................................................................

44

+O[no]rotating_fpregs........................................................................................................

45

+O[no]sumreduction..........................................................................................................

45

Header File Options...............................................................................................................

45

-H....................................................................................................................................

45

4Contents

+hdr_create......................................................................................................................

45

+hdr_use..........................................................................................................................

45

-I directory........................................................................................................................

45

-I-.....................................................................................................................................

46

Online Help Option................................................................................................................

47

+help...............................................................................................................................

47

Inlining Options.....................................................................................................................

48

+inline_level num...............................................................................................................

48

Library Options......................................................................................................................

49

-b....................................................................................................................................

49

-dynamic...........................................................................................................................

49

-exec................................................................................................................................

49

-lname..............................................................................................................................

49

-L directory........................................................................................................................

50

-minshared........................................................................................................................

50

+nostl...............................................................................................................................

50

+Onolibcalls=...................................................................................................................

50

Linker Options........................................................................................................................

50

-e epsym...........................................................................................................................

50

-n.....................................................................................................................................

50

-N....................................................................................................................................

51

+O[no]dynopt...................................................................................................................

51

-q....................................................................................................................................

51

-Q....................................................................................................................................

51

-r.....................................................................................................................................

51

-s.....................................................................................................................................

51

-usymbol...........................................................................................................................

51

+ild..................................................................................................................................

52

+ildrelink..........................................................................................................................

52

Options for Naming the Output File..........................................................................................

52

-o.....................................................................................................................................

52

-.suffix..............................................................................................................................

52

Native Language Support Option.............................................................................................

52

-Y.....................................................................................................................................

52

Handling Null Pointers Options................................................................................................

53

-z.....................................................................................................................................

53

-Z....................................................................................................................................

53

Code Optimizing Options.......................................................................................................

53

Basic Optimization Level Options.........................................................................................

53

-O...............................................................................................................................

54

+O0............................................................................................................................

54

+O1............................................................................................................................

54

+O2............................................................................................................................

54

+O3............................................................................................................................

54

+O4............................................................................................................................

55

Object Files Generated at Optimization Level 4............................................................

55

Additional Optimization Options for Finer Control..................................................................

55

-ipo.............................................................................................................................

56

Object Files Generated with -ipo................................................................................

56

+[no]nrv......................................................................................................................

56

+O[no]failsafe..............................................................................................................

56

+O[no]aggressive.........................................................................................................

57

+O[no]limit..................................................................................................................

57

+O[no]ptrs_to_globals[=list]...........................................................................................

57

+O[no]size...................................................................................................................

57

Contents 5

Advanced +Ooptimization Options......................................................................................

57

+O[no]cross_region_addressing......................................................................................

58

+O[no]datalayout.........................................................................................................

58

+O[no]dataprefetch.......................................................................................................

58

+O[no]fltacc.................................................................................................................

58

+Ofrequently_called......................................................................................................

59

+O[no]initcheck............................................................................................................

59

+O[no]inline................................................................................................................

60

+Olit...........................................................................................................................

60

+Ointeger_overflow.......................................................................................................

60

+Olevel.......................................................................................................................

61

+O[no]loop_transform...................................................................................................

61

+O[no]loop_unroll........................................................................................................

61

+O[no]openmp.............................................................................................................

61

+opts...........................................................................................................................

62

+O[no]parminit............................................................................................................

62

+O[no]parmsoverlap.....................................................................................................

62

+O[no]procelim............................................................................................................

62

+O[no]promote_indirect_calls.........................................................................................

62

+Orarely_called............................................................................................................

63

+O[no]signedpointers....................................................................................................

63

+Oshortdata................................................................................................................

63

+O[no]store_ordering....................................................................................................

64

+Otype_safety..............................................................................................................

64

+Ounroll_factor............................................................................................................

64

Profile-Based Optimization Options......................................................................................

64

+Oprofile.....................................................................................................................

64

Information Embedding Options..........................................................................................

65

-annotate=structs...........................................................................................................

65

Displaying Optimization Information.....................................................................................

65

+O[no]info...................................................................................................................

65

Parallel Processing Options......................................................................................................

65

-mt...................................................................................................................................

66

+O[no]autopar..................................................................................................................

67

+tls=[static|dynamic]..........................................................................................................

67

+wlock.............................................................................................................................

68

Performance Options...............................................................................................................

68

-fast..................................................................................................................................

68

+Ofast..............................................................................................................................

68

+Ofaster...........................................................................................................................

69

+O[no]tls_calls_change_tp..................................................................................................

69

+[no]srcpos.......................................................................................................................

69

+DSmodel........................................................................................................................

69

Porting Options......................................................................................................................

70

-fast..................................................................................................................................

70

+sb..................................................................................................................................

70

+ub..................................................................................................................................

70

+uc..................................................................................................................................

70

+w64bit...........................................................................................................................

71

+wdriver...........................................................................................................................

71

+wendian.........................................................................................................................

71

Preprocessor Options..............................................................................................................

72

-C....................................................................................................................................

72

-dM..................................................................................................................................

72

-Dname............................................................................................................................

72

6Contents

-E.....................................................................................................................................

72

Redirecting Output From This Option...............................................................................

72

make[d]............................................................................................................................

73

+Make[d].........................................................................................................................

73

-P.....................................................................................................................................

73

-Uname............................................................................................................................

74

Profiling Code Options............................................................................................................

74

-G....................................................................................................................................

74

-p....................................................................................................................................

74

+profilebucketsize..............................................................................................................

74

Runtime Checking Options.......................................................................................................

75

+check.............................................................................................................................

75

+check=all........................................................................................................................

75

+check=none....................................................................................................................

75

+check=bounds.................................................................................................................

75

+check=globals.................................................................................................................

78

+check=lock......................................................................................................................

78

+check=malloc..................................................................................................................

79

+check=stack[:frame|:variables|:none]................................................................................

80

+check=thread..................................................................................................................

80

+check=truncate[:explicit|:implicit].......................................................................................

81

+check=uninit ...................................................................................................................

81

Standards Related Options......................................................................................................

82

-Aa..................................................................................................................................

82

-AA..................................................................................................................................

82

-Aarm...............................................................................................................................

82

-AC89..............................................................................................................................

83

-AC99..............................................................................................................................

83

-Ae..................................................................................................................................

83

-Ag++..............................................................................................................................

83

-Agcc...............................................................................................................................

83

-AOa and -AOe.................................................................................................................

84

-AP..................................................................................................................................

84

-Ax..................................................................................................................................

84

+legacy_cpp.....................................................................................................................

84

+legacy_v5.......................................................................................................................

84

+std=c89|c99|c++98|c++11|gcc|g++|gnu.......................................................................

85

+stl=rw|none....................................................................................................................

85

+tru64..............................................................................................................................

86

-Wc,-ansi_for_scope,[on|off]...............................................................................................

86

-Wc,-koenig_lookup,[on|off]................................................................................................

86

Subprocesses of the Compiler..................................................................................................

87

-tx,name...........................................................................................................................

87

More Examples of -t.......................................................................................................

87

-Wx,args..........................................................................................................................

88

Passing Options to the Linker with -W...............................................................................

89

Passing Multiple Options to the Linker with -W..................................................................

89

Symbol Binding Options..........................................................................................................

89

-Bdefault...........................................................................................................................

89

-Bextern............................................................................................................................

89

-Bhidden...........................................................................................................................

90

-Bhidden_def.....................................................................................................................

90

-Bprotected........................................................................................................................

90

-Bprotected_data................................................................................................................

90

-Bprotected_def..................................................................................................................

90

Contents 7

-Bsymbolic.........................................................................................................................

91

Template Options...................................................................................................................

91

+[no]dep_name.................................................................................................................

91

+inst_compiletime..............................................................................................................

91

+inst_directed....................................................................................................................

91

+inst_implicit_include.........................................................................................................

91

+inst_include_suffixes.........................................................................................................

92

Trigraph Processing Suppression Option....................................................................................

92

-notrigraph........................................................................................................................

93

Verbose Compile and Link Information.......................................................................................

93

-dumpversion.....................................................................................................................

93

+dryrun............................................................................................................................

93

+O[no]info.......................................................................................................................

93

+wsecurity........................................................................................................................

93

+time...............................................................................................................................

93

-v.....................................................................................................................................

94

-V....................................................................................................................................

94

Concatenating Options...........................................................................................................

95

3 Pragma Directives and Attributes................................................................

96

Initialization and Termination Pragmas......................................................................................

96

INIT.................................................................................................................................

96

FINI.................................................................................................................................

96

Copyright Notice and Identification Pragmas..............................................................................

97

COPYRIGHT......................................................................................................................

97

COPYRIGHT_DATE.............................................................................................................

97

LOCALITY.........................................................................................................................

97

LOCALITY_ALL...................................................................................................................

97

VERSIONID.......................................................................................................................

98

Data Alignment Pragmas.........................................................................................................

98

ALIGN.............................................................................................................................

98

PACK ..............................................................................................................................

98

Basic Example............................................................................................................

100

Template Example.......................................................................................................

100

Handling Unaligned Data............................................................................................

101

Implicit Access to Unaligned Data.................................................................................

101

UNALIGN.......................................................................................................................

102

Optimization Pragmas...........................................................................................................

103

OPT_LEVEL Pragma..........................................................................................................

103

OPTIMIZE Pragma...........................................................................................................

103

FLOAT_TRAPS_ON Pragma...............................................................................................

103

[NO]INLINE Pragma........................................................................................................

104

NO_INLINE Pragma........................................................................................................

104

IVDEP Pragma.................................................................................................................

105

NODEPCHK Pragma........................................................................................................

105

NO_RETURN Pragma.......................................................................................................

105

Diagnostic Pragmas..............................................................................................................

105

diag_xxx Pragmas...........................................................................................................

105

Other Pragmas.....................................................................................................................

105

assert Pragma.................................................................................................................

105

BINDING Pragma............................................................................................................

106

DEFAULT_BINDING Pragma..............................................................................................

106

ESTIMATED_FREQUENCY Pragma.....................................................................................

106

EXTERN Pragma..............................................................................................................

106

FREQUENTLY_CALLED Pragma..........................................................................................

106

8Contents

HDR_STOP Pragma..........................................................................................................

107

HIDDEN Pragma.............................................................................................................

107

HP_DEFINED_EXTERNAL Pragma......................................................................................

107

HP_DEFINED_INTERNAL Pragma.......................................................................................

107

IF_CONVERT Pragma.......................................................................................................

107

POP Pragma...................................................................................................................

108

Pragma (once).................................................................................................................

108

PROTECTED Pragma........................................................................................................

108

PTRS_STRONGLY_TYPED Pragma.......................................................................................

108

PTRS_TO_GLOBALS Pragma..............................................................................................

108

PUSH Pragma.................................................................................................................

108

RARELY_CALLED Pragma..................................................................................................

108

STDC CX_LIMITED_RANGE Pragma...................................................................................

109

STDC FLOAT_CONST_DECIMAL64 Pragma .......................................................................

109

STDC FP_CONTRACT Pragma...........................................................................................

109

STDC FENV_ACCESS Pragma...........................................................................................

110

UNROLL_FACTOR Pragma................................................................................................

110

OMP ATOMIC Pragma.....................................................................................................

110

OMP BARRIER Pragma.....................................................................................................

111

OMP CRITICAL Pragma....................................................................................................

111

OMP FOR Pragma...........................................................................................................

111

OMP FLUSH Pragma........................................................................................................

111

OMP MASTER Pragma.....................................................................................................

112

OMP ORDERED Pragma...................................................................................................

112

OMP PARALLEL Pragma....................................................................................................

112

OMP PARALLEL FOR Pragma.............................................................................................

112

OMP PARALLEL SECTIONS Pragma....................................................................................

113

OMP SECTIONS Pragma..................................................................................................

113

OMP SINGLE Pragma......................................................................................................

113

OMP TASK Pragma..........................................................................................................

113

OMP TASKWAIT Pragma..................................................................................................

114

OMP THREADPRIVATE Pragma..........................................................................................

114

OpenMP Clauses.................................................................................................................

114

private............................................................................................................................

 

114

firstprivate.......................................................................................................................

114

lastprivate.......................................................................................................................

114

copyprivate.....................................................................................................................

115

if...................................................................................................................................

 

115

default............................................................................................................................

 

115

shared............................................................................................................................

 

115

copyin............................................................................................................................

 

115

reduction........................................................................................................................

115

nowait............................................................................................................................

 

115

ordered..........................................................................................................................

 

116

schedule.........................................................................................................................

 

116

num_threads...................................................................................................................

116

Attributes.............................................................................................................................

 

116

attribute

aligned..............................................................................................................

116

attribute malloc................................................................................................................

116

attribute

non_exposing.....................................................................................................

117

attribute

noreturn.............................................................................................................

117

attribute format................................................................................................................

118

attribute visibility..............................................................................................................

118

attribute warn_unused_result..............................................................................................

118

Contents 9

4 Preprocessing Directives..........................................................................

119

Overview of the Preprocessor.................................................................................................

119

Syntax............................................................................................................................

119

Usage Guidelines............................................................................................................

119

Source File Inclusion (#include, #include_next).....................................................................

120

Syntax.......................................................................................................................

120

Description.................................................................................................................

120

Examples...................................................................................................................

121

Macro Replacement (#define, #undef)................................................................................

121

Syntax.......................................................................................................................

121

Description.................................................................................................................

121

Macros with Parameters...............................................................................................

121

Specifying String Literals with the # Operator..................................................................

122

Concatenating Tokens with the ## Operator ..................................................................

122

Example 1.............................................................................................................

122

Example 2.............................................................................................................

123

Using Macros to Define Constants.................................................................................

123

Other Macros.............................................................................................................

123

Example 1.............................................................................................................

124

Example 2.............................................................................................................

124

Using Constants and Inline Functions Instead of Macros...................................................

124

Example................................................................................................................

124

Predefined Macros......................................................................................................

125

Assertions (#assert, #unassert)...........................................................................................

125

Syntax.......................................................................................................................

125

Description.................................................................................................................

125

Conditional Compilation (#if, #ifdef, .. #endif)....................................................................

126

Syntax.......................................................................................................................

126

Description.................................................................................................................

126

Using the defined Operator..........................................................................................

127

Using the #if Directive..................................................................................................

127

The #endif Directive.....................................................................................................

127

Using the #ifdef and #ifndef Directives...........................................................................

127

Nesting Conditional Compilation Directives....................................................................

127

Using the #else Directive..............................................................................................

127

Using the #elif Directive...............................................................................................

127

Examples...................................................................................................................

128

Line Control (#line)...........................................................................................................

128

Syntax.......................................................................................................................

128

Description.................................................................................................................

128

Example....................................................................................................................

128

IOSTREAM Performance Improvement Pragma.....................................................................

129

Syntax:......................................................................................................................

129

Pragma Directive (#pragma) and _Pragma Operator............................................................

129

Syntax.......................................................................................................................

129

Description.................................................................................................................

129

Example....................................................................................................................

129

Error Directive (#error)......................................................................................................

130

Syntax.......................................................................................................................

130

Example....................................................................................................................

130

Warning Directive............................................................................................................

130

Syntax.......................................................................................................................

130

Trigraph Sequences..........................................................................................................

130

Examples........................................................................................................................

130

10 Contents

5 Using HP aC++ Templates.......................................................................

132

Invoking Compile-Time Instantiation.........................................................................................

132

Scope and Precedence.....................................................................................................

132

Template Processing.........................................................................................................

132

Explicit Instantiation..........................................................................................................

133

Usage.......................................................................................................................

133

Performance...............................................................................................................

133

Examples...................................................................................................................

133

Class Template.......................................................................................................

133

Function Template...................................................................................................

134

Command-Line Option Instantiation....................................................................................

134

Compile-Time Instantiation.................................................................................................

134

Why Use Compile-Time Instantiation..............................................................................

135

Scope........................................................................................................................

135

Usage.......................................................................................................................

135

Migrating from Automatic Instantiation to Compile-time Instantiation.......................................

135

Possible Duplicate Symbols in Shared Libraries................................................................

135

Possible Duplicate Symbols in Archive Libraries................................................................

135

Building an Archive Library with +inst_auto/+inst_close...............................................

136

Building an Archive Library with Compile-time Instantiation..........................................

136

C++ Template Tutorial......................................................................................................

136

Class Templates..........................................................................................................

136

Function Templates......................................................................................................

137

6 Standardizing Your Code........................................................................

138

HP aC++ Keywords..............................................................................................................

138

bool Keyword..................................................................................................................

138

Usage.......................................................................................................................

138

Example....................................................................................................................

138

dynamic_cast Keyword.....................................................................................................

139

Usage.......................................................................................................................

139

Example....................................................................................................................

139

explicit Keyword..............................................................................................................

141

Usage.......................................................................................................................

141

Example....................................................................................................................

141

mutable Keyword.............................................................................................................

143

Usage.......................................................................................................................

143

Example....................................................................................................................

143

namespace and using Keywords........................................................................................

144

Connections Across Translation Units.............................................................................

144

An Auxiliary Translation Unit.........................................................................................

145

usingdeclarations and usingdirectives.........................................................................

145

usingdeclaration...................................................................................................

145

usingdirective.......................................................................................................

145

typeid Keyword...............................................................................................................

146

Usage.......................................................................................................................

146

typeid Example......................................................................................................

146

volatile Keyword..............................................................................................................

148

Usage.......................................................................................................................

148

Example....................................................................................................................

148

wchar_t Keyword.............................................................................................................

149

Usage.......................................................................................................................

149

Example....................................................................................................................

149

template Keyword............................................................................................................

149

Usage.......................................................................................................................

149

Contents 11

Example....................................................................................................................

149

typename Keyword..........................................................................................................

149

Usage.......................................................................................................................

149

Example....................................................................................................................

149

Overloading new[] and delete[] for Arrays...............................................................................

150

Example.........................................................................................................................

151

Standard Exception Classes...................................................................................................

152

Example.........................................................................................................................

152

Exceptions Thrown by the Standard C++ Library.......................................................................

153

type_info Class.....................................................................................................................

153

Unsupported Functionality......................................................................................................

154

7 Optimizing HP aC++ Programs................................................................

156

Requesting Optimization........................................................................................................

156

Setting Basic Optimization Levels.......................................................................................

156

Level 1 Optimization....................................................................................................

156

Level 2 Optimization....................................................................................................

156

Level 3 Optimization....................................................................................................

157

Level 4 Optimization....................................................................................................

157

Additional Options for Finer Control...................................................................................

157

Enabling Aggressive Optimizations................................................................................

157

Enabling Only Conservative Optimizations.....................................................................

158

Removing Compilation Time Limits When Optimizing.......................................................

158

Limiting the Size of Optimized Code..............................................................................

158

Combining Optimization Options..................................................................................

158

Profile-Based Optimization................................................................................................

158

Instrumentation...........................................................................................................

159

Collecting Data for Profiling..........................................................................................

159

Maintaining Profile Data Files.......................................................................................

159

Example 1.................................................................................................................

160

Example 2.................................................................................................................

160

Performing Profile-Based Optimization............................................................................

160

Pragmas That Control Optimization.........................................................................................

160

8 Exception Handling................................................................................

161

Exception Handling..............................................................................................................

161

Exception Handling in C++...............................................................................................

161

Exception Handling as Defined by the ANSI/ISO C++ International Standard.........................

162

Basic Exception Handling Example....................................................................................

162

Function Try Block Examples..............................................................................................

162

Debugging Exception Handling.........................................................................................

163

Performance Considerations..............................................................................................

163

Using Threads......................................................................................................................

163

Rogue Wave Standard C++ Library 2.2.1...........................................................................

163

Rogue Wave Standard C++ Library 1.2.1 and Tools.h++ 7.0.6..............................................

163

Using Locks.....................................................................................................................

163

Required Command-line Options.......................................................................................

164

Rogue Wave Standard C++ Library 2.2.1.......................................................................

164

Rogue Wave Standard C++ Library 1.2.1 and Tools.h++ 7.0.6..........................................

164

Limitations.......................................................................................................................

165

Using -D_THREAD_SAFE with the cfront Compatible libstream...........................................

165

Differences between Standard iostreams and cfront Compatible libstream...........................

165

Using -D__HPACC_THREAD_SAFE_RB_TREE...................................................................

165

Exception Handling..........................................................................................................

166

Pthreads (POSIX Threads).......................................................................................................

166

Limitations.......................................................................................................................

166

12 Contents

Function Scoping..................................................................................................................

167

Performance Options.............................................................................................................

167

Parallel Programming Using OpenMP......................................................................................

167

OpenMP Implementation..................................................................................................

167

OpenMP Header File...................................................................................................

168

OpenMP Library.........................................................................................................

168

+O[no]openmp Command Line Option..........................................................................

169

_OPENMP Macro.......................................................................................................

169

Environment Variables in OpenMP.....................................................................................

169

OMP_SCHEDULE........................................................................................................

169

OMP_NUM_THREADS................................................................................................

169

OMP_DYNAMIC.........................................................................................................

170

OMP_NESTED............................................................................................................

170

Runtime Library Functions in OpenMP.................................................................................

170

Execution Environment Functions........................................................................................

170

omp_set_num_threads..................................................................................................

171

omp_get_num_threads.................................................................................................

171

omp_get_max_threads.................................................................................................

171

omp_get_thread_num..................................................................................................

171

omp_get_num_procs....................................................................................................

171

omp_in_parallel..........................................................................................................

171

omp_set_dynamic.......................................................................................................

172

omp_get_dynamic.......................................................................................................

172

omp_set_nested..........................................................................................................

172

omp_get_nested..........................................................................................................

172

Lock Functions.................................................................................................................

172

omp_init_lock and omp_init_nest_lock...........................................................................

173

omp_destroy_lock and omp_destroy_nest_lock................................................................

173

omp_set_lock and omp_set_nest_lock............................................................................

173

omp_unset_lock and omp_unset_nest_lock......................................................................

173

omp_test_lock and omp_test_nest_lock Functions.............................................................

174

Timing Functions..............................................................................................................

174

omp_get_wtime..........................................................................................................

174

omp_get_wtick............................................................................................................

174

9 Tools and Libraries..................................................................................

175

HP Specific Features of lex and yacc.......................................................................................

175

Creating and Using Libraries..................................................................................................

175

HP aC++ Libraries...........................................................................................................

176

Standard C++ Library..................................................................................................

176

Introduction................................................................................................................

176

Introduction to Using the Standard C++ Library...............................................................

176

Differences between Standard C++ Library and Other Libraries.........................................

177

The Non-Object-Oriented Design of the Standard C++ Library..........................................

177

Smaller Source Code..............................................................................................

178

Flexibility...............................................................................................................

178

Efficiency...............................................................................................................

178

Iterators: Mismatches and Invalidations.....................................................................

178

Templates: Errors and Code Bloat.............................................................................

178

Multithreading Problems..........................................................................................

178

Standard C++ Library Reference...................................................................................

178

Incompatibilities Between the Library and the Standard....................................................

178

Tools.h++ Library........................................................................................................

179

HP aC++ Runtime Support Library.................................................................................

179

IOStream Library.........................................................................................................

179

Contents 13

Standard Components Library Not Provided...................................................................

179

Linking to C++ Libraries...............................................................................................

180

Linking with Shared or Archive Libraries.........................................................................

180

Specifying Other Libraries............................................................................................

180

Creating and Using Shared Libraries..................................................................................

180

Compiling for Shared Libraries......................................................................................

180

Example................................................................................................................

180

Creating a Shared Library............................................................................................

181

Example................................................................................................................

181

Using a Shared Library................................................................................................

181

Example................................................................................................................

181

Example of Creating and Using a Shared Library............................................................

181

Linking Archive or Shared Libraries................................................................................

181

Syntax..................................................................................................................

182

Example................................................................................................................

182

Updating a Shared Library...........................................................................................

182

Advanced Shared Library Features.....................................................................................

182

Forcing the Export of Symbols in main...........................................................................

182

Binding Times.............................................................................................................

183

Forcing Immediate Binding......................................................................................

183

Side Effects of C++ Shared Libraries..............................................................................

183

Routines and Options to Manage C++ Shared Libraries...................................................

183

Linker Options to Manage Shared Libraries....................................................................

183

Version Control for Shared Libraries...............................................................................

183

Adding New Versions to a Shared Library......................................................................

184

Standard HP-UX Libraries and Header Files.........................................................................

184

Location of Standard HP-UX Header Files.......................................................................

184

Using Header Files......................................................................................................

184

Example................................................................................................................

184

Allocation Policies for Containers.......................................................................................

184

For -AP Standard Library..............................................................................................

184

For -AA Standard Library..............................................................................................

185

HP aC++ File Locations.........................................................................................................

186

HP aC++ Executable Files.................................................................................................

186

HP aC++ Runtime Libraries and Header Files.......................................................................

187

10 Mixing C++ with Other Languages.........................................................

188

Calling Other Languages.......................................................................................................

188

Data Compatibility between C and C++.................................................................................

188

HP aC++ Calling HP C.....................................................................................................

189

Using the extern "C" Linkage Specification.....................................................................

189

Syntax of extern "C"....................................................................................................

189

Examples of extern "C"................................................................................................

189

Differences in Argument Passing Conventions..................................................................

190

The main() Function.....................................................................................................

190

Examples: HP aC++ Calling HP C.................................................................................

190

Running the Example..............................................................................................

191

HP C Calling HP aC++.....................................................................................................

191

Compiling and Running the Sample Programs.................................................................

192

Calling HP FORTRAN 90 from HP aC++.............................................................................

193

The main() Function.....................................................................................................

193

Function Naming Conventions......................................................................................

193

Using Reference Variables to Pass Arguments..................................................................

193

Example of Reference Variables as Arguments............................................................

193

Using extern "C" Linkage.............................................................................................

194

14 Contents

Strings.......................................................................................................................

194

Arrays.......................................................................................................................

194

Files in FORTRAN........................................................................................................

194

11 Distributing Your C++ Products................................................................

195

Applications that use HP aC++ Shared Libraries.......................................................................

195

Linking Your HP aC++ Libraries with Other Languages..............................................................

196

Installing your Application.....................................................................................................

196

HP aC++ Files You May Distribute..........................................................................................

196

Terms for Distribution of HP aC++ Files....................................................................................

197

12 Migrating from HP C++ (cfront) to HP aC++.............................................

198

General Guidelines for Migration...........................................................................................

198

Getting Started with Migration...........................................................................................

198

Writing Code for both Compilers.......................................................................................

199

Explicit Loading and Unloading of Shared Libraries .............................................................

199

Memory Allocation..........................................................................................................

199

Command-Line Differences.....................................................................................................

199

New Command-Line Options.............................................................................................

199

Obsolete Command-Line Options.......................................................................................

200

Changed Command-Line Options......................................................................................

201

Migration Considerations when Debugging.............................................................................

202

Migration Considerations when Using Exception Handling.........................................................

202

Exception Handling is the Default.......................................................................................

202

Memory Allocation Failure and operator new......................................................................

203

Possible Differences when Exiting a Signal Handler..............................................................

203

Differences in setjmp/longjmp Behavior..............................................................................

204

Calling unexpected..........................................................................................................

204

Unreachable catch Clauses...............................................................................................

205

Throwing an Object having an Ambiguous Base Class..........................................................

205

Migration Considerations when Using Libraries.........................................................................

206

Standards Based Libraries.................................................................................................

206

HP C++ (cfront) Compatibility Libraries...............................................................................

207

IOStream Library.........................................................................................................

207

Manpages.............................................................................................................

207

Header Files..........................................................................................................

207

Standard Components Library Not Provided...................................................................

208

HP C++ (cfront) Complex Library Not Supported.............................................................

208

Manpages.............................................................................................................

208

Header File...........................................................................................................

208

HP C++ (cfront) Task Library Not Supported...................................................................

208

Manpages.............................................................................................................

208

Migration Considerations Related to Preprocessing...................................................................

208

Obsolete Preprocessor Options..........................................................................................

209

Migration Considerations Related to Standardization.................................................................

209

Changes in C++ Semantics...............................................................................................

209

Implicit Typing of Character String Literals.......................................................................

209

Overload Resolution Ambiguity of Subscripting Operator.................................................

210

Execution Order of Static Constructors in Shared Libraries.................................................

210

More Frequent Inlining of Inline Code............................................................................

211

Changes in C++ Syntax....................................................................................................

211

Explicit int Declaration.................................................................................................

211

The for Statement, New Scoping Rules...........................................................................

212

struct as Template Type Parameter is Permitted.................................................................

212

Base Template Class Reference Syntax Change...............................................................

213

Tokens after #endif......................................................................................................

213

Contents 15

overload not a Keyword...............................................................................................

213

Dangling Comma in enum...........................................................................................

214

Static Member Definition Required.................................................................................

214

Declaring friend Classes...............................................................................................

214

Incorrect Syntax for Calls to operator new......................................................................

215

Using :: in Class Definitions..........................................................................................

215

Duplicate Formal Argument Names...............................................................................

215

Ambiguous Function or Object Declaration.....................................................................

215

Overloaded Operations ++ and --.................................................................................

216

Reference Initialization.................................................................................................

216

Using operator new to Allocate Arrays...........................................................................

217

Parentheses in Static Member Initialization List.................................................................

217

&qualified-id Required in Static Member Initialization List..................................................

218

Non-constant Reference Initialization..............................................................................

218

Digraph White Space Separators..................................................................................

219

Migration Considerations when Using Templates......................................................................

219

Verbose Template Processing Information............................................................................

219

Common Template Migration Syntax Changes.....................................................................

220

The cfront Implicit Include Convention.................................................................................

220

Converting Directed Mode to Explicit Instantiation................................................................

220

13 Documentation feedback.......................................................................

221

A Diagnostic Messages..............................................................................

222

aC++ Message Catalog........................................................................................................

222

Command Errors..............................................................................................................

222

Command Warnings........................................................................................................

222

Fatal Errors.....................................................................................................................

222

Future Errors....................................................................................................................

222

Anachronisms..................................................................................................................

222

Warnings.......................................................................................................................

222

Suggestion/Information....................................................................................................

222

Tool Errors......................................................................................................................

222

Frequently Encountered Messages...........................................................................................

222

Glossary..................................................................................................

223

Index.......................................................................................................

227

16 Contents

HP secure development lifecycle

Starting with HP-UX 11i v3 March 2013 update release, HP secure development lifecycle provides the ability to authenticate HP-UX software. Software delivered through this release has been digitally signed using HP's private key. You can now verify the authenticity of the software before installing the products, delivered through this release.

To verify the software signatures in signed depot, the following products must be installed on your system:

B.11.31.1303 or later version of SD (Software Distributor)

A.01.01.07 or later version of HP-UX Whitelisting (WhiteListInf)

To verify the signatures, run: /usr/sbin/swsign -v –s <depot_path>. For more information, see Software Distributor documentation at http://www.hp.com/go/sd-docs.

NOTE: Ignite-UX software delivered with HP-UX 11i v3 March 2014 release or later supports verification of the software signatures in signed depot or media, during cold installation.

For more information, see Ignite-UX documentation at http://www.hp.com/go/ignite-ux-docs.

About This Document

This manual presents programming information on the C++ programming language, as implemented on Itanium®- based systems.

The document printing date and part number indicate the document’s current edition. The printing date will change when a new edition is printed. Minor changes may be made at reprint without changing the printing date. The document part number will change when extensive changes are made.

Document updates may be issued between editions to correct errors or document product changes. To ensure that you receive the updated or new editions, you should subscribe to the appropriate product support service. Contact your HP sales representative for details.

The latest version of this document is available on the web at http://www.hp.com/go/ hpux-C-Integrity-docs.

Intended Audience

This manual is intended for experienced C and C++ programmers who are familiar with HP systems.

What’s in This Document

HP aC++/HP C Programmer’s Guide is divided into the following chapters:

Chapter 1

Getting Started

 

Gives you an introduction to the HP aC++ product and its components. It also

 

discusses the compiler command syntax and environment variables.

Chapter 2

Command Line Options

 

Discusses command line options. Command line options are categorized into

 

different sections based on how you can use them. This chapter also covers

 

diagnostic messages and pragma directives.

Chapter 3

Pragma Directives

 

Discusses pragmas supported in HP aC++. A pragma directive is an instruction

 

to the compiler. Use a #pragma directive to control the actions of the compiler

 

in a particular portion of a translation unit without affecting the translation unit

 

as a whole.

Chapter 4

Preprocessing Directives

 

Gives you an overview, the syntax, and usage guidelines of preprocessing

 

directives. This chapter also includes a section on using HP aC++ templates.

Chapter 5

Using HP aC++ Templates

 

Gives you an overview of template processing and describes the instantiation

 

coding methods available in HP aC++.

Chapter 6

Standardizing Your Code

 

Discusses HP aC++ keywords, Standard Exception Classes, and exceptions

 

thrown by the Standard C++ library, and lists unsupported functionality.

Chapter 7

Optimizing HP aC++ Programs

 

Gives you information about optimizing your programs.

Chapter 8

Exception Handling

 

Discusses exception handling, and information on using threads and parallel

 

programming.

18

Chapter 9 Tools and Libraries

Discusses the tools and libraries bundled with HP aC++.

Chapter 10 Mixing C++ with Other Languages

Provides guidelines for linking HP aC++ modules with modules written in HP C and HP FORTRAN 90 on HP systems.

Chapter 11 Distributing Your C++ Products

Provides distribution-related information for C++ products. If you choose to distribute archive libraries or object files, your customer must have purchased HP aC++. Make sure that your customer has read this distribution information.

Chapter 12 Migrating from HP C++ (cfront) to HP aC++

Discusses differences in syntax and functionality that you may need to consider, when migrating code from HP C++ (cfront) to HP aC++.

Appendix A Diagnostic Messages

Discusses the aCC message catalog and frequently encountered messages. The aC++ compiler can issue a large variety of diagnostics in response to unexpected situations or suspicious constructs.

Glossary

Contains definitions of terms used in this book, listed alphabetically.

Typographical Conventions

This document uses the following conventions.

audit(5)

An HP-UX manpage. In this example, audit is the name and 5 is the section in

 

the HP-UX Reference respectively. On the Web and on the Instant Information

 

CD, it may be a hot link to the manpage itself. From the HP-UX command line,

 

you can enter “man audit” or “man 5 audit” to view the manpage. See

 

man(1).

Book Title

The title of a book. On the Web and on the Instant Information CD, it may be

 

a hot link to the book itself.

KeyCap

The name of a keyboard key.

Emphasis

Emphasized text.

Bold

Strongly emphasized text.

Bold

The defined use of an important word or phrase.

ComputerOut

Text displayed by the computer.

UserInput

Commands and other text that you type.

Command

A command name or qualified command phrase.

Variable

The name of a variable that you may replace in a command or function or

 

information in a display that represents several possible values.

[]

The contents are optional in syntax. If the contents are a list separated by |,

 

you must choose one of the items.

{}

The contents are required in syntax. If the contents are a list separated by |,

 

you must choose one of the items.

...

The preceding element may be repeated an arbitrary number of times.

|Separates items in a list of choices.

What’s in This Document 19

HP C-aC++ User's Guide

HP-UX Release Name and Release Identifier

Each HP-UX 11i release has an associated release name and release identifier. Theuname(1) command with the -r option returns the release identifier. This table shows the releases available for HP-UX 11i.

Table 1 HP-UX 11i Releases

Release Identifier

Release Name

Supported Processor Architecture

B.11.31

HP-UX 11i v3.0

Intel® Itanium®

B.11.11

HP-UX 11i v1

PA-RISC

B.11.23

HP-UX 11i v2.0

PA-RISC

B.11.31

HP-UX 11i v3.0

PA-RISC

B.11.20

HP-UX 11i v1.5

Intel® Itanium®

B.11.22

HP-UX 11i v1.6

Intel® Itanium®

B.11.23

HP-UX 11i v2.0

Intel® Itanium®

B.11.31

HP-UX 11i v3.0

Intel® Itanium®

Publishing History

Edition

Release Date

Product Version

13

March 2014

HP aC++ v A.06.28

12

September 2012

HP aC++ v A.06.27

11

September 2011

HP aC++ v A.06.26

10

March 2010

HP aC++ v A.06.25

9

September 2009

HP aC++ v A.06.20

8

September 2007

HP aC++ v A.06.15

7

November 2006

HP aC++ v A.06.12

6

May 2006

HP aC++ v A.06.10

5

September 2005

HP aC++ v A.06.05

4

December 2004

HP aC++ v A.06.00/A.05.60

3

September 2004

HP aC++ v A.05.55.02

2

March 2004

HP aC++ v A.05.55

1

August 2003

HP aC++ v A.05.50

Related Documents

You can fine additional information about the HP aC++/HP C compiler on the web at http:// www.hp.com/go/hpux-C-Integrity-docs.

20

The following is a list of documents available with this release:

HP aC++/HP ANSI C Release Notes

This document gives an overview of new command-line options and features in HP aC++ and HP C compilers for Itanium®-based systems.

HP C/HP-UX Reference Manual

This manual presents reference information on the C and C++ programming languages.

HP Encourages Your Comments

HP encourages your comments concerning this document. We are truly committed to providing documentation that meets your needs.

Please send comments to: c++-editor@cup.hp.com

Please include document title, manufacturing part number, and any comment, error found, or suggestion for improvement that you have about this document.

HP Encourages Your Comments 21

1 Getting Started with HP aC++

The information in this document applies to the release of HP aC++ and HP ANSI C compilers version A.06.28 for the HP-UX 11i v3 operating system.

The HP ANSI C compiler supports ANSI programming language C standard ISO 9899:1999. HP aC++ compiler supports the ISO/IEC 14882 Standard for the C++ Programming Language (the international standard for C++).

Version A.06.28 of the HP aC++/HP C compiler provides leading edge support for C++11 standard language features, with complete binary compatibility with earlier releases and -AA compilation mode.

This chapter discusses the following topics:

“Components of the Compilation System” (page 22)

“Compiler Command Syntax and Environmental Variables” (page 24)

“Files on the aCC Command Line” (page 25)

“Environment Variables” (page 26)

“Floating Installation” (page 29)

Components of the Compilation System

The HP aC++ compiling system consists of the following components:

aCC The aCC driver is the only supported interface to HP aC++ and to the linker for HP aC++ object files.

cc cc is the HP-UX C compiler.

c89 c89 is the HP-UX ANSI-conforming C89 compiler. c99 c99 is the HP-UX ANSI-conforming C99 compiler.

ecom The ecom compiler (for A.06.*) compiles the C++ source statements. Preprocessing is incorporated into the compiler.

ctcom The ctcom compiler (for A.05.*) compiles the C++ source statements. Preprocessing is incorporated into the compiler.

The other HP aC++ executable files are:

c++filt

c++filt is the name demangler. It implements the name demangling algorithm which

 

encodes function name, class name, and parameter number and name.

ld

ld is the linker. It links executables and builds shared libraries.

HP aC++ Runtime Libraries and Header Files:

Standard C++ Library

/usr/lib/hpux32/libstd.so (32-bit shared version) /usr/lib/hpux32/libstd.a (32-bit archive version) /usr/lib/hpux64/libstd.so (64-bit shared version) /usr/lib/hpux64/libstd.a (64-bit archive version)

HP aC++ Runtime Support Library /usr/lib/hpux##/libCsup.so

/usr/lib/hpux##/libCsup11.so — ISO C++11 standard compliant /usr/lib/hpux##/libstd.so and libstd_v2.so /usr/lib/hpux##/libstd_v2.so and librwtool_v2.so /usr/lib/hpux##/libstream.so

Libraries in /usr/include/hpux##

(where ## is 32 or 64 provided as part of the HP-UX core system)

22 Getting Started with HP aC++

Standard C++ Library

/usr/lib/hpux32/libstream.so (32-bit shared version) /usr/lib/hpux32/libstream.a (32-bit archive version) /usr/lib/hpux64/libstream.so (64-bit shared version) /usr/lib/hpux64/libstream.a (64-bit archive version)

Header files for these libraries are located at /opt/aCC/include/.

Using the aCC Command

To invoke the HP aC++ compiling system, use the aCC command at the shell prompt. TheaCC command invokes a driver program that runs the compiling system according to the filenames and command line options that you specify.

Compiling a Simple Program

The best way to get started with HP aC++ is to write, compile, and execute a simple program, as shown in the following example:

#include <iostream.h> int main()

{

int x,y;

cout << “Enter an integer: “; cin >> x;

y = x * 2;

cout << “\n” << y <<“ is twice “ << x <<“.\n”;

}

If this program is in the file getting_started.C, compiling and linking the program with the aCC command produces an executable file named a.out, by default:

$ aCC getting_started.C

Executing the Program

To run this executable file, just enter the name of the file. The following summarizes this process with the file getting_started.C:

$ a.out

Enter an integer: 7 14 is twice 7.

Debugging Programs

You can use programming and debugging aides.

HP Code Advisor

HP Code Advisor is a code checking tool that can be used to detect programming errors in C/C++ source code. Use "/opt/cadvise/bin/cadvise" to invoke the tool. A brief description is available with the -help option.

$ /opt/cadvise/bin/cadvise -help

Additional information is available at: http://www.hp.com/go/cadvise/.

HP WDB Debugger

You can also use the HP WDB debugger to debug your C++ programs after compiling your program with either the -g, the -g0, or the -g1 option.

Example:

The -g0 option enables generation of debug information:

$ aCC -g0 program.C

Components of the Compilation System 23

The gdb command runs the HP WDB debugger:

$ gdb a.out

For more information on the HP WDB debugger, refer to “Debugging Options” (page 35).

Accessing Online Example Source Files

Online example source files are located in the directory /opt/aCC/contrib/Examples/ RogueWave. These include examples for the Standard C++ Library and for the Tools.h++ Library.

Compiler Command Syntax and Environmental Variables

The aCC command (the driver) invokes the HP aC++ compiling system. The aCC command is followed by options and files that need to be compiled.

aCC [options] [files]

You must use the aCC command to link your C++ programs and libraries. This ensures that all libraries and other files needed by the linker are available.

Example:

aCC prog.C

This command compiles the source file prog.C and puts the executable code in the file a.out.

For a complete list of command line options, see Chapter 2: “Command-Line Options” (page 31).

Examples of the aCC Command

Following are some examples of the aCC command:

Compiling and Renaming an Output File

aCC -o prog prog.C

This command compiles prog.C and puts the executable code in the file prog, rather than in the default file a.out.

Compiling and Debugging

aCC -g prog.C

This command compiles prog.C and includes information that allows you to debug the program with the HP WDB debugger, wdb.

Compiling Without Linking

aCC -c prog.C

This command compiles prog.C and puts the object code in the file prog.o. It neither links the object file nor creates an executable file.

Linking Object Files

aCC file1.o file2.o file3.o

This command links the listed object files (file1.o, file2.o, and file3.o) and puts the executable code in the file a.out.

NOTE: You must use the aCC command to link your HP aC++ programs and libraries. This ensures that all libraries and other files needed by the linker are available.

Compiling, Optimizing, and Getting Verbose Information

aCC -O -v prog.C

24 Getting Started with HP aC++

This command compiles and optimizes prog.C, gives verbose progress reports, and creates an executable file a.out.

Compiling and Creating a Shared Library

aCC +z -c prog.C

aCC -b -o mylib.sl prog.o

The first line compiles prog.C, creates the object file prog.o, and puts the position-independent code (PIC) into the object file. The second line creates the shared library mylib.sl, and puts the executable code into the shared library.

Files on the aCC Command Line

Files containing source or object code to be compiled or linked by HP aC++ can be any of these files:

A C++ Source File (.C file)

Preprocessed Source Files (.i Files)

Assembly Language Source Files (.s Files)

Object Files (.o Files)

Library Files (.a and .so Files)

“Configuration Files (.conf Files)” (page 26)

Unless you use the -o option to specify otherwise, all files that the aCC compiling system generates are put in the working directory, even if the source files are from other directories.

C++ Source File (.C file)

You must name the HP aC++ source files with extensions beginning with either .c or .C, possibly followed by additional characters. If you compile only, for example by using -c, each C++ source file produces an object file with the same file name prefix as the source file and a .o file name suffix.

However, if you compile and link a single source file into an executable program in one step, the

.o file is automatically deleted, unless -g is used without +noobjdebug.

NOTE: HP recommends that your source files have .c or .C extensions only, without any additional characters. While extensions other these are permitted for portability from other systems, they may not be supported by HP tools and environments.

Preprocessed Source Files (.i Files)

Files with .i extensions are assumed to be preprocessor output files. These files are processed in the same way as .c or .C files, except that the preprocessor is not run on the .i file before the file is compiled.

Use the -P or the -E compiler option to preprocess a C++ source file without compiling it.

Assembly Language Source Files (.s Files)

Files with names ending in .s are assumed to be assembly source files. The compiler invokes the assembler through cc to create .o files from these.

Use the -S option to compile a C++ source file to assembly code and put the assembly code into a .s file.

Files on the aCC Command Line 25

Object Files (.o Files)

Files with .o extensions are assumed to be relocatable object files that have to be included in the linking. The compiler invokes the linker to link the object files and create an executable file.

Use the -c option to compile a C++ source file into a .o file.

Library Files (.a and .so Files)

Files ending with .a are assumed to be archive libraries. Files ending with .so are assumed to be shared libraries.

Use the -c and +z options to create object files of Position-Independent Code (PIC) and the -b option to create a shared library.

Use the -c option to create object files and the ar command to combine the object files into an archive library.

Configuration Files (.conf Files)

You can configure compiler options on a system-wide basis. The compiler reads the configuration files:

/var/aCC/share/aCC.conf (aC++), or

/var/ansic/share/cc.conf(ANSI C), if present.

In C-mode, the configuration file defaults to/var/ansic/share/cc.conf, unless overridden by the environment variable CC_CONFIG..

In C++ mode, the config file defaults to /var/aCC/share/aCC.conf, unless overriden by the environment variable CXX_CONFIG.

The options in the configuration file can be specified in the same manner as that for CCOPTS and CXXOPTS, namely:

[options-list-1] [|[options-list-2]]

where options in options-list-1 are applied before the options in the command line, and options in options-list-2 are applied after the options in the command line.

The final option ordering would be:

<file-options-1><envvar-options-1><command-line-options>

<envvar-options-2><file-options-2>

NOTE: No configuration files are shipped along with aC++, but can be installed by the system administrator, if required.

The config file options before the "|" character set the defaults for compilations, and the options after the character override the user’s command line settings.

Environment Variables

This section describes the following environment variables that you can use to control the HP aC++ or HP C compiler:

“aCC_FULL_PATHNAMES Environment Variable” (page 27)

“aCC_MAXERR Environment Variable” (page 27)

“CXXOPTS Environment Variable” (page 27)

“CCLIBDIR Environment Variable” (page 27)

“CCROOTDIR Environment Variable” (page 28)

26 Getting Started with HP aC++

“CXX_MAP_FILE Environment Variable” (page 29)

“TMPDIR Environment Variable” (page 29)

aCC_FULL_PATHNAMES Environment Variable

Exporting the aCC_FULL_PATHNAMES variable causes the compiler to include full path names for files in compiler messages. This feature is useful in debugging.

aCC_MAXERR Environment Variable

The aCC_MAXERR environment variable allows you to set the maximum number of errors you want the compiler to report before it terminates compilation. The default is 100.

CXXOPTS Environment Variable

The CXXOPTS environment variable provides a convenient way to include frequently used command-line options automatically.

Options before the vertical bar (|) are placed before command-line options to aCC. The options after the vertical bar are placed after any command-line option. Note that the vertical bar must be delimited by white space.

If you do not use the vertical bar, all options are placed before the command line parameters. Set the environment variable and the options you want are automatically included each time you execute the aCC command.

Syntax:

export CXXOPTS="options | options" ksh/sh notation

setenv CXXOPTS "options | options" csh notation

Usage:

For quick or temporary changes to your build environment, use CXXOPTS instead of editing your makefiles.

Example:

export CXXOPTS="-v | -lm" ksh/sh notation

setenv CXXOPTS "-v | -lm" csh notation

The above command causes the -v and -l options to be passed to the aCC command each time you execute it.

When CXXOPTS is set as above, the following two commands are equivalent:

aCC -g prog.C

aCC -v -g prog.C -lm

CCLIBDIR Environment Variable

The CCLIBDIR environment variable causes the aCC command to search for libraries in an alternate directory before searching in the default directories.

Syntax:

export

CCLIBDIR=directory

ksh/sh notation

setenv

CCLIBDIR directory

csh notation

directory is an HP-UX directory where you want HP aC++ to look for libraries.

Example:

export CCLIBDIR=/mnt/proj/lib

In this example HP aC++ searches the directory /mnt/proj/lib for libraries before searching the directory /opt/aCC/lib.

Environment Variables

27

When CCLIBDIR is set a in the above example, the following two commands are equivalent:

aCC -L/mnt/proj/lib file.o

aCC file.o

NOTE: You can use the -Ldirectory option to specify additional directories for the linker to search for libraries.

CCROOTDIR Environment Variable

The CCROOTDIR environment variable causes aCC to invoke all subprocesses from an alternate aCC directory, rather than from their default directory. The default aCC root directory is /opt/ aCC.

Syntax:

export

CCROOTDIR=directory

ksh/sh notation

setenv

CCROOTDIR directory

csh notation

directory is an aCC root directory where you want the HP aC++ driver to search for subprocesses.

Example:

28 Getting Started with HP aC++

export CCROOTDIR=/mnt/CXX2.1

In this example, HP aC++ searches the directories under /mnt/CXX2.1 (/mnt/CXX2.1/bin and /mnt/CXX2.1/lbin) for subprocesses rather than their respective default directories.

CXX_MAP_FILE Environment Variable

To facilitate easy migration of build environment from a different compiler to HP aC++, an option mapping support is provided. You can use the option mapping files to map the options in the third party compilers to HP aC++ equivalents. The mapping file is a text file that defines the mapping rules. The compiler reads the mapping file and applies the specified replacements to the options on the command line. This minimizes the need to make Makefile or script changes. The CXX_MAP_FILE environment variable allows you to change the location of the mapping file.

Syntax:

export CXX_MAP_FILE=file path

Example:

export CXX_MAP_FILE=/home/src/my_option.map

The example specifies that HP aC++ should use mapping file from file path specified using CXX_MAP_FILE.

Defining the Mapping Rules:

Following is the syntax for defining the rules in the mapping file:

LHS => RHS

where:

Left Hand Side (LHS) is the third party compiler option.

Right Hand Side (RHS) is the HP aC++ compiler option

NOTE: Ensure to use a space before and after "=>".

To define rules for options that have arguments, use the $<number> wildcard.

For Example:

$1 for the first argument, and $2 for the second. If the third party compiler option (LHS) does not match with any HP aC++option, leave the RHS blank.

TMPDIR Environment Variable

The TMPDIR environment variable allows you to change the location of temporary files created by the compiler. The default directory is /var/tmp.

Syntax:

export

TMPDIR=directory

ksh/sh notation

setenv

TMPDIR directory

csh notation

directory is the name of an HP-UX directory where you want HP aC++ to put temporary files during compilation.

Example:

export

TMPDIR=/mnt/temp

ksh

notation

setenv

TMPDIR /mnt/temp

csh

notation

The above example specifies that HP aC++ should put all temporary files in /mnt/temp.

Floating Installation

More than one version of the HP aC++ compiler can be installed on one system at the same time. The floating installation feature allows you to install the compiler in any location. You can install as many compiler versions as required, depending on your system’s resources.

Floating Installation

29

HP aC++

By default, HP aC++ is installed under the /opt/aCC directory. In earlier releases, the compiler driver (aCC) looked for related files in subdirectories of the /opt/aCC directory. This prevented installation of more than one version of HP aC++ on the same system at the same time.

Only files in /opt/aCC are affected by floating installation. Regardless of the HP aC++ driver you use, the compiler still uses the libraries, linker, and other files located in /usr/lib and /usr/ ccs.

Floating installation is designed to help facilitate in-house development. You must not ship libraries in non-standard places, because explicit runtime library specifications and linker options are required.

You can use the __HP_aCC predefined macro to determine which version is being run.

HP C

You can use the __HP_cc predefined macro to determine which version is being run.

NOTE: Do not use floating installation with the following:

CCROOTDIR environment variable

-tc,name command line option

Setting up Floating Installation

You may want to install the most recent compiler version and keep the prior version on one system. If there are problems with the most recent version, you can easily switch to the prior one. Following is an example of how to set up the floating installation feature for this purpose. Assume that your system will have two versions of the compiler, both floating install enabled. In this case, A.05.50 is the prior version, and A.05.60 or A.06.00 is the more recent version.

To setup floating installation, complete the following steps:

1.Copy the prior version to another directory. cp -rp /opt/aCC /opt/aCC.05.55

2.Use swinstall to install the new version (A.06.00 or A.05.60 in this case).

30 Getting Started with HP aC++

Loading...
+ 200 hidden pages