Sie sind auf Seite 1von 362
iSeries WebSphere ® Development Studio C/C++ Language Reference SC09-4815-00

iSeries

WebSphere ® Development Studio C/C++ Language Reference

SC09-4815-00

iSeries WebSphere ® Development Studio C/C++ Language Reference SC09-4815-00
iSeries WebSphere ® Development Studio C/C++ Language Reference SC09-4815-00
iSeries WebSphere ® Development Studio C/C++ Language Reference SC09-4815-00
iSeries WebSphere ® Development Studio C/C++ Language Reference SC09-4815-00
iSeries WebSphere ® Development Studio C/C++ Language Reference SC09-4815-00

iSeries

WebSphere ® Development Studio C/C++ Language Reference

SC09-4815-00

Note! Before using this information and the product it supports, be sure to read the

Note! Before using this information and the product it supports, be sure to read the general information under “Notices” on page 339.

this information and the product it supports, be sure to read the general information under “Notices”

First Edition (May 2001)

This edition applies to Version 5, Release 1, Modification 0, of IBM WebSphere Development Studio for iSeries (program 5722-WDS), ILE C/C++ compilers, and to all subsequent releases and modifications until otherwise indicated in new editions. This edition replaces ILE C for AS/400 Language Reference (SC09–2711–01) and VisualAge C++ for OS/400 C++ Language Reference (SC09–2121–00).

Order publications through your IBM representative or the IBM branch office serving your locality. Publications are not stocked at the address given below.

IBM welcomes your comments. You can send comments to:

IBM Canada Ltd. Laboratory,

2G/KB7/1150/TOR

1150 Eglinton Avenue East Toronto, Ontario, Canada. M3C 1H7

You can also send your comments by facsimile (attention: RCF Coordinator), or you can send your comments electronically to IBM.

When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you.

© Copyright International Business Machines Corporation 1998, 2001. All rights reserved. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

Contents

About This Reference .

 

.

.

.

.

.

.

.

vii

. How to Read the Syntax Diagrams

Highlighting Conventions

.

.

 

.

.

.

.

.

.

.

.

.

.

.

.

vii

vii

Chapter 1. Scope and Linkage .

 

.

.

.

.1

Scope .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1

Local Scope.

.

.

.

.

.

.

.

.

.

.

.

.

.

1

. Function Prototype Scope .

Function Scope

.

.

.

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.2

.2

Global Scope

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.2

Class Scope .

Name Hiding .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3

3

Program Linkage .

.

.

.

.

.

.

.

.

.4

Internal Linkage

External Linkage .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.4

.5

No Linkage .

.

.

.

.

.

.

.

.

.

.

.

.

.6

Linkage Specifications Linking to Non-C++

 

Programs

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6

Chapter 2. Lexical Elements .

 

.

.

.

.

.9

Tokens .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

9

Source Program Character Set

.

.

.

.

.

.

.

.9

Escape Sequences

.

.

.

.

.

.

.

.

.

.

.

10

The Unicode Standard .

.

.

.

.

.

.

.

.

.

11

Trigraph Sequences .

.

.

.

.

.

.

.

.

.

.

12

Comments.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

12

Identifiers .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

14

Case Sensitivity and Special Characters in

 

Identifiers .

.

.

.

.

.

.

.

.

.

.

.

.

.

15

. Alternative Tokens .

Keywords .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

15

16

Literals .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

16

. Floating-Point Literals .

Integer Literals

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

17

18

Character Literals

.

.

.

.

.

.

.

.

.

.

.

20

String Literals

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

20

Boolean Literals .

.

.

.

.

.

.

.

22

Chapter 3. Declarations

.

.

.

.

.

.

.

23

Declarations Overview

.

.

.

.

.

.

.

.

.

.

23

. Storage Class Specifiers

Objects .

.

.

.

.

.

.

.

.

.

.

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

24

24

.

.

.

.

.

.

.

25

auto Storage Class Specifier . extern Storage Class Specifier

. mutable Storage Class Specifier .

 

.

.

.

.

.

.

.

.

.

.

.

.

25

27

register Storage Class Specifier .

.

.

.

.

.

.

27

static Storage Class Specifier.

.

.

.

.

.

.

.

28

typedef

.

.

.

.

.

.

.

.

.

.

.

.

29

Type Specifiers

.

.

.

.

.

.

.

.

.

.

.

.

.

30

Simple Type Specifiers.

.

.

.

.

.

.

.

.

.

31

Structures .

.

.

.

.

.

.

.

.

.

.

.

.

.

36

Unions

.

.

.

.

.

.

.

.

.

.

.

.

42

Enumerations.

.

.

.

.

.

.

.

.

.

.

.

.

46

volatile and const Qualifiers .

.

.

.

.

.

.

.

50

Incomplete Types

.

.

.

.

.

.

.

.

.

.

.

51

Chapter 4. Declarators .

.

.

.

.

.

.

.

55

Initializers .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

56

Pointers

. Declaring Pointers .

.

.

.

.

.

.

.

.

Restrictions on Pointers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

58

58

Assigning Pointers .

.

.

.

.

.

.

59

Initializing Pointers .

.

.

.

.

.

.

59

.

.

.

.

.

.

60

. Pointer Arithmetic .

Using Pointers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

60

60

Example Program Using Pointers .

.

.

.

.

.

61

Arrays .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

62

Declaring Arrays

.

.

.

.

.

.

.

.

.

.

.

63

. Example Programs Using Arrays

Initializing Arrays

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

64

66

Function Specifiers .

.

.

.

.

.

.

.

.

.

.

.

68

References .

. Initializing References .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

68

69

Chapter 5. Expressions and Operators

 

71

Operator Precedence and Associativity

.

.

.

.

.

71

Examples of Expressions and Precedence

.

.

.

74

Lvalues and Rvalues .

.

.

.

.

.

.

.

.

.

.

75

Integer Constant Expressions

.

.

.

.

.

.

.

.

75

Primary Expressions .

. Parenthesized Expressions ( )

. C++ Scope Resolution Operator :: .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

76

76

77

Postfix Expressions .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

78

Function Calls ( )

.

.

.

.

.

.

78

Array Subscript [ ] (Array Element Specification)

80

Dot Operator .

.

.

.

.

.

.

.

.

.

.

.

.

81

.

.

.

.

.

.

.

.

.

.

82

Arrow Operator −> static_cast Operator.

. reinterpret_cast Operator .

.

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

82

83

const_cast Operator.

.

 

.

.

.

.

.

.

.

.

.

84

dynamic_cast Operator

.

.

.

.

.

.

.

.

.

85

Unary Expressions .

.

.

.

.

.

.

.

.

.

.

.

86

Increment ++ .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

87

Decrement −−

.

.

.

.

.

.

.

.

.

.

88

Unary Plus + .

Unary Minus − .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

88

89

Logical Negation !

.

.

.

.

.

.

.

.

.

.

89

Bitwise Negation ˜ .

.

.

.

.

.

.

.

.

.

.

89

Address & .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

90

Indirection *

.

.

.

.

.

.

.

.

.

.

90

sizeof (Size of an Object) .

 

.

.

.

.

.

.

.

.

91

C++ new Operator .

.

.

.

.

.

.

.

.

.

.

92

C++ delete Operator

.

.

.

.

.

.

.

.

.

.

95

Allocation and Deallocation Functions

 

.

.

.

.

96

Binary Expressions .

.

.

.

.

.

.

.

.

.

.

.

.

97

Multiplication * .

.

.

.

.

.

.

.

.

.

.

98

Division / .

.

.

.

.

.

.

.

.

.

.

.

.

.

99

.

.

.

.

.

.

.

.

.

.

.

.

99

Remainder % . Addition + Subtraction −

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

99

100

Bitwise Left and Right Shift << >>

.

.

.

.

.

100

Relational < > <= >= .

.

.

.

.

.

.

.

.

.

101

Block Statement

.

.

.

.

.

.

.

.

.

.

.

.

145

Equality == != .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

102

if Statement .

.

.

.

.

.

.

.

.

.

.

.

.

.

146

Bitwise AND &.

Bitwise Exclusive OR |

.

.

.

.

.

.

.

.

.

.

103

104

switch Statement

while Statement

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

148

151

Bitwise Inclusive OR |

.

.

.

.

.

104

do Statement

.

.

.

.

.

.

.

.

.

.

.

.

.

152

Logical AND && .

.

.

.

.

.

.

.

.

.

.

105

for Statement

.

.

.

.

.

.

.

.

.

.

.

.

.

153

Logical OR ||

.

.

.

.

.

.

.

.

.

.

.

.

105

break Statement

.

.

.

.

.

.

.

.

.

.

.

.

155

C++ Pointer to Member Operators .* >* .

 

.

.

106

continue Statement

.

.

.

.

.

.

.

.

.

.

.

156

Assignment Expressions .

.

.

.

.

.

.

.

.

107

return Statement

.

.

.

.

.

.

.

.

.

.

.

.

158

. C++ throw Expressions .

Cast Expressions .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

108

109

Value of a return Expression and Function Value 158

159

.

.

.

.

.

.

.

.

.

.

.

.

Conditional Expressions .

Type of Conditional C Expressions

.

.

.

.

.

.

.

.

.

.

109

110

goto Statement . Null Statement .

.

.

.

.

.

.

.

.

.

.

.

.

160

Type of Conditional C++ Expressions

The typeid operator

.

.

.

.

.

.

 

.

.

.

.

110

Chapter 9. Preprocessor Directives

 

161

Examples of Conditional Expressions

.

.

.

.

.

.

.

.

111

111

. Preprocessor Directive Format .

Preprocessor Overview .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

161

162

. Comma Expression , .

.

.

.

.

.

.

.

.

.

.

113

Macro Definition and Expansion (#define) .

 

.

.

.

162

 

Object-Like Macros

.

.

.

.

.

.

.

.

.

.

.

.

.

162

Chapter 6. Implicit Type Conversions

 

115

Function-Like Macros

.

.

.

.

.

.

163

Integral and Floating-Point Promotions .

 

.

.

.

.

115

Scope of Macro Names (#undef) .

.

.

.

.

.

.

165

Standard Type Conversions.

.

.

.

.

.

.

.

.

116

# Operator

.

.

.

.

.

.

.

.

.

.

.

166

Lvalue-to-Rvalue Conversions .

.

.

.

.

.

.

117

Macro Concatenation with the ## Operator

 

.

.

.

167

Boolean Conversions .

.

.

.

.

.

.

.

.

.

.

.

.

.

117

Preprocessor Error Directive (#error).

.

.

.

.

.

168

Integral Conversions .

.

.

.

.

.

117

File Inclusion (#include) .

.

.

.

.

.

.

.

.

.

168

Floating-Point Conversions .

.

.

.

.

.

.

.

118

ANSI/ISO Standard Predefined Macro Names

 

.

.

169

Pointer Conversions .

.

.

.

.

.

.

.

.

.

.

.

.

.

118

Conditional Compilation Directives .

.

.

.

.

.

170

Reference Conversions

.

.

.

.

.

119

#if, #elif

.

.

.

.

.

.

.

.

.

.

.

.

.

.

172

Pointer-to-Member Conversions

.

.

.

.

.

.

119

#ifdef .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

172

Qualification Conversions

.

.

.

.

.

.

.

.

120

#ifndef

.

.

.

.

.

.

.

.

.

.

.

.

.

.

173

Function Argument Conversions .

.

.

.

.

.

120

#else .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

173

. Arithmetic Conversions .

Other Conversions

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

120

121

. Examples of Conditional Compilation Directives

#endif .

.

.

.

.

.

.

.

.

.

.

.

.

.

174

174

The explicit Keyword.

.

.

.

.

.

.

.

.

.

.

121

Line Control (#line) .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

174

Chapter 7. Functions .

.

.

.

.

.

.

.

123

Null Directive (#) .

Pragma Directives (#pragma) .

.

.

.

.

.

.

.

.

.

.

.

.

175

176

C++ Enhancements to C Functions

Function Declarations

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.