Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Jones D.M.The new C standard (C90 and C++).An economic and cultural commentary.2005

.pdf
Скачиваний:
19
Добавлен:
23.08.2013
Размер:
1.36 Mб
Скачать

5.2.4.1 Translation limits 283

All characters are significant. 20)

C identifiers that differ after the last significant character will cause a diagnostic to be generated by a C++ translator.

The following is a non-normative specification.

Number of initial characters in an internal identifier or a macro name [1024]

280 — 31 significant initial characters in an external identifier (each universal character name specifying a short identifier of 0000FFFF or less is considered 6 characters, each universal character name specifying a short identifier of 00010000 or more is considered 10 characters, and each extended source character is considered the same number of characters as the corresponding universal character name, if any)14)

Annex Bp2

external identifier significant

characters

C90

6 significant initial characters in an external identifier

C++

2.10p1

All characters are significant. 20)

C identifiers that differ after the last significant character will cause a diagnostic to be generated by a C++ translator.

The following is a non-Normative specification.

 

 

Number of initial characters in an external identifier [1024]

 

Annex Bp2

 

 

 

 

 

 

 

 

 

 

 

 

 

282 — 4095 external identifiers in one translation unit

 

limit

C90

 

external identifiers

 

 

 

 

 

 

 

 

 

511 external identifiers in one translation unit

 

 

 

 

 

 

C++

 

 

The following is a non-normative specification.

 

 

 

 

 

 

Annex Bp2

 

 

External identifiers in one translation unit [65536]

 

 

 

 

 

 

 

 

 

 

September 2, 2005

v 1.0b

286

5.2.4.1 Translation limits

 

 

 

 

 

 

identifiers

— 511 identifiers with block scope declared in one block

283

number in block scope

C90

127 identifiers with block scope declared in one block

C++

The following is a non-normative specification.

Annex Bp2

Identifiers with block scope declared in one block [1024]

limit

— 4095 macro identifiers simultaneously defined in one preprocessing translation unit

284

macro definitions

C90

 

 

 

 

 

 

 

 

 

 

 

 

1024 macro identifiers simultaneously defined in one translation unit

 

 

 

 

 

 

 

 

C++

 

 

 

The following is a non-normative specification.

 

 

Annex Bp2

 

 

 

 

 

Macro identifiers simultaneously defined in one translation unit [65536]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

limit

— 127 parameters in one function definition

285

parameters in

 

 

 

 

definition

C90

 

 

 

 

 

 

 

 

 

31 parameters in one function definition

 

 

 

 

 

 

 

 

C++

 

 

 

The following is a non-normative specification.

 

 

Annex Bp2

 

 

 

 

 

Parameters in one function definition [256]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

function call

— 127 arguments in one function call

286

number of argu-

 

 

 

 

ments

C90

 

 

v 1.0b

September 2, 2005

5.2.4.1 Translation limits 289

31 arguments in one function call

C++

The following is a non-normative specification.

Arguments in one function call [256]

287 — 127 parameters in one macro definition

C90

31 parameters in one macro definition

C++

The following is a non-normative specification.

Parameters in one macro definition [256]

288 — 127 arguments in one macro invocation

C90

31 arguments in one macro invocation

C++

The following is a non-normative specification.

Arguments in one macro invocation [256]

289 — 4095 characters in a logical source line

C90

509 characters in a logical source line

C++

The following is a non-normative specification.

Annex Bp2

limit macro parameters

Annex Bp2

limit arguments in

macro invocation

Annex Bp2

limit characters on line

Annex Bp2

September 2, 2005

v 1.0b

293 5.2.4.1 Translation limits

Characters in a logical source line [65536]

limit

— 4095 characters in a character string literal or wide string literal (after concatenation)

290

string literal

C90

 

 

 

 

 

 

 

 

 

 

 

 

509 characters in a character string literal or wide string literal (after concatenation)

 

 

 

 

 

 

 

 

C++

 

 

 

The following is a non-normative specification.

 

 

Annex Bp2

 

 

 

 

 

Characters in a character string literal or wide string literal (after concatenation) [65536]

 

 

 

 

 

 

 

 

 

 

 

limit

— 65535 bytes in an object (in a hosted environment only)

291

minimum object

C90

 

 

size

 

 

 

 

 

 

 

 

 

32767 bytes in an object (in a hosted environment only)

 

 

 

 

 

 

 

 

C++

 

 

 

The following is a non-normative specification.

 

 

Annex Bp2

 

 

 

 

 

Size of an object [262144]

 

 

 

 

 

 

 

 

 

 

limit

— 15 nesting levels for #included files

292

#include nest-

 

 

 

 

ing

C90

 

 

 

 

 

 

 

 

 

8 nesting levels for #included files

 

 

 

 

 

 

 

 

C++

 

 

 

The following is a non-normative specification.

 

 

Annex Bp2

 

 

 

 

 

Nesting levels for #included files [256]

 

 

 

 

 

 

 

 

 

 

limit

— 1023 case labels for a switch statement (excluding those for any nested switch statements)

293

case labels

C90

 

 

 

 

 

v 1.0b

September 2, 2005

5.2.4.1 Translation limits 296

257 case labels for a switch statement (excluding those for any nested switch statements)

The intent here was to support switch statements that included 256 unsigned character values plus EOF switchstatement (usually implemented as -1).

C++

The following is a non-normative specification.

 

 

Case labels for a switch statement (excluding those for any nested switch statements) [16384]

 

Annex Bp2

 

 

 

 

 

 

 

 

 

 

 

 

 

294 — 1023 members in a single structure or union

 

limit

 

 

 

 

members in

C90

 

struct/union

 

 

 

 

 

 

 

127 members in a single structure or union

 

 

 

 

 

 

C++

 

 

The following is a non-normative specification.

Data members in a single class, structure or union [16384]

295 — 1023 enumeration constants in a single enumeration

C90

127 enumeration constants in a single enumeration

C++

The following is a non-normative specification.

Enumeration constants in a single enumeration [4096]

296 — 63 levels of nested structure or union definitions in a single struct-declaration-list

C90

15 levels of nested structure or union definitions in a single struct-declaration-list

C++

Annex Bp2

limit enumeration constants

Annex Bp2

limit struct/union nesting

The following is a non-normative specification.

Annex Bp2

September 2, 2005

v 1.0b

320

5.2.4.2.1 Sizes of integer types <limits.h>

Levels of nested class, structure, or union definitions in a single struct-declaration-list [256]

5.2.4.2 Numerical limits

numerical limits An implementation is required to document all the limits specified in this subclause, which are specified in 297 the headers <limits.h> and <float.h>.

C90

A conforming implementation shall document all the limits specified in this subclause, which are specified in the headers <limits.h> and <float.h>.

C++

18.2.2p2

Header <climits> (Table 16): . . . The contents are the same as the Standard C library header <limits.h>.

18.2.2p4

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>.

Additional limits are specified in <stdint.h>.

298

C90

Support for these limits and the header that contains them is new in C99.

C++

Support for these limits and the header that contains them is new in C99 and is not available in C++.

5.2.4.2.1 Sizes of integer types <limits.h>

integer types sizes

17.4.4.2p2

The values given below shall be replaced by constant expressions suitable for use in #if preprocessing 300 directives.

C++

All object-like macros defined by the Standard C library and described in this clause as expanding to integral constant expressions are also suitable for use in #if preprocessing directives, unless explicitly stated otherwise.

18.2.2p2

Header <climits> (Table 16): . . . The contents are the same as the Standard C library header <limits.h>

v 1.0b

September 2, 2005

 

5.2.4.2.2 Characteristics of floating types

<float.h>

334

 

 

 

 

 

 

 

 

 

 

 

320 — minimum value for an object of type long long int

 

 

long long int

 

 

 

 

minimum value

LLONG_MIN -9223372036854775807 // -(263-1)

 

 

LLONG_MIN

 

 

 

 

C90

Support for the type long long and its associated macros is new in C99.

C++

The type long long is not available in C++ (although many implementations support it).

321 — maximum value for an object of type long long int

LLONG_MAX +9223372036854775807 // 263-1

C90

Support for the type long long and its associated macros is new in C99.

C++

The type long long is not available in C++ (although many implementations support it).

322 — maximum value for an object of type unsigned long long int

ULLONG_MAX 18446744073709551615 // 264-1

C90

Support for the type unsigned long long and its associated macros is new in C99.

C++

The type unsigned long long is not available in C++.

325 The value UCHAR_MAX shall equal 2CHAR_BIT − 1.

C90

This requirement was not explicitly specified in the C90 Standard.

C++

Like C90, this requirement is not explicitly specified in the C ++ Standard.

5.2.4.2.2 Characteristics of floating types <float.h>

327The characteristics of floating types are defined in terms of a model that describes a representation of floatingpoint numbers and values that provide information about an implementation’s floating-point arithmetic. 16)

C++

UCHAR_MAX value

floating types characteristics

18.2.2p4

Header <cfloat> (Table 17): . . . The contents are the same as the Standard C library header <float.h>

332 p precision (the number of base-b digits in the significand)

precision

C++

floating-point

 

The term significand is not used in the C++ Standard.

 

September 2, 2005

v 1.0b

337

5.2.4.2.2 Characteristics of floating types <float.h>

 

 

 

 

 

 

334

floating-point

A floating-point number (x ) is defined by the following model:

model

 

 

 

 

p

emin ≤ e ≤ emax

 

 

 

x = sbe

fkb−k,

 

 

 

 

 

 

kP

 

 

 

 

 

 

 

 

 

=1

 

 

 

 

 

 

C90

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

A normalized floating-point number x (f1 > 0 if x 6= 0) is defined by the following model:

 

 

 

 

 

 

 

p

fk×b−k, emin ≤ e ≤ emax

 

 

 

 

 

 

 

x = s×be×

 

 

 

 

 

 

 

kP

 

 

 

 

 

 

 

 

 

=1

 

 

 

 

The C90 Standard did not explicitly deal with subnormal or unnormalized floating-point numbers.

floating types can represent

NaN

C++

The C++ document does not contain any description of a floating-point model. But, Clause 18.2.2 explicitly refers the reader to ISO C90 subclause 5.2.4.2.2

In addition to normalized floating-point numbers ( f1 > 0 if x 6= 0), floating types may be able to contain

335

other kinds of floating-point numbers, such as subnormal floating-point numbers ( x 6= 0, e = emin, f1 = 0)

 

and unnormalized floating-point numbers ( x 6= 0, e > emin, f1 = 0), and values that are not floating-point

 

numbers, such as infinities and NaNs.

 

C90

 

The C90 Standard does not mention these kinds of floating-point numbers. However, the execution environ-

 

ments for C90 programs are likely to be the same as C99 in terms of their support for IEC 60559.

 

C++

 

The C++ Standard does not go into this level of detail.

 

 

 

336

A NaN is an encoding signifying Not-a-Number.

C90

 

This concept was not described in the C90 Standard.

 

C++

Although this concept was not described in C90, C++ does include the concept of NaN.

18.2.1.2p34 Tem-

plate class nu- static const bool has_quiet_NaN; meric_limits

True if the type has a representation for a quiet (non-signaling) “Not a Number.” 193)

18.2.2.1p37

static const bool has_signaling_NaN;

True if the type has a representation for a signaling “Not a Number.” 194)

NaN

A quiet NaN propagates through almost every arithmetic operation without raising a floating-point exception; 337

raising an ex-

 

 

ception

 

 

 

v 1.0b

September 2, 2005

5.2.4.2.2 Characteristics of floating types <float.h> 343

C90

The concept of NaN was not discussed in the C90 Standard.

C++

18.2.1.2p34

static const bool has_quiet_NaN;

True if the type has a representation for a quiet (non-signaling) “Not a Number.” 193)

338 a signaling NaN generally raises a floating-point exception when occurring as an arithmetic operand. 17)

C++

static const bool has_signaling_NaN;

True if the type has a representation for a signaling “Not a Number.” 194

342 16) The floating-point model is intended to clarify the description of each floating-point characteristic and does not require the floating-point arithmetic of the implementation to be identical.

18.2.1.2p37

footnote 16

C++

The C++ Standard does not explicitly describe a floating-point model. However, it does include the template class numeric_limits. This provides a mechanism for accessing the values of many, but not all, of the characteristics used by the C model to describe its floating-point model.

343 The accuracy of the floating-point operations ( +, -, *, /) and of the library functions in <math.h> and <complex.h> that return floating-point results is implementation-defined , as is the accuracy of the conversion between float - ing-point internal representations and string representations performed by the library routine in <stdio.h>,

<stdlib.h> and <wchar.h>.

C90

In response to DR #063 the Committee stated (while the Committee did revisit this issue during the C99 revision of the C Standard, there was no change of requirements):

floating-point

operations accuracy

DR #063

Probably the most useful response would be to amend the C Standard by adding two requirements on implementations:

Require that an implementation document the maximum errors it permits in arithmetic operations and in evaluating math functions. These should be expressed in terms of “units in the least-significant position” (ULP) or “lost bits of precision.”

Establish an upper bound for these errors that all implementations must adhere to. The state of the art, as the Committee understands it, is:

correctly rounded results for arithmetic operations (no loss of precision)

1 ULP for functions such as sqrt, sin, and cos (loss of 1 bit of precision)

4–6 ULP (loss of 2–3 bits of precision) for other math functions.

September 2, 2005

v 1.0b

347

5.2.4.2.2 Characteristics of floating types <float.h>

 

 

 

 

 

 

 

Since not all commercially viable machines and implementations meet these exacting requirements, the C

 

 

 

 

Standard should be somewhat more liberal.

 

 

 

 

The Committee would, however, suggest a requirement no more liberal than a loss of 3 bits of precision, out

 

 

 

 

of kindness to users. An implementation with worse performance can always conform by providing a more

 

 

 

 

conservative version of <float.h>, even if that is not a desirable approach in the general case. The Committee

 

 

 

 

should revisit this issue during the revision of the C Standard.

 

 

 

 

 

 

C++

The C++ Standard says nothing on this issue.

 

The implementation may state that the accuracy is unknown.

344

 

C++

 

 

The C++ Standard does not explicitly give this permission.

 

 

 

 

 

float.h

All integer values in the <float.h> header, except FLT_ROUNDS, shall be constant expressions suitable for use

345

constant ex-

in #if preprocessing directives;

 

pressions

 

float.h

 

 

 

suitable for #if

C90

 

Of the values in the <float.h> header, FLT_RADIX shall be a constant expression suitable for use in #if preprocessing directives;

C99 requires a larger number of values to be constant expressions suitable for use in a #if preprocessing directive and in static and aggregate initializers.

C++

The requirement in C++ only applies if the header <cfloat> is used (17.4.1.2p3). While this requirement does not apply to the contents of the header <float.h>, it is very likely that implementations will meet it and no difference is flagged here. The namespace issues associated with using <cfloat> do not apply to names defined as macros in C (17.4.1.2p4)

17.4.4.2p2

All object-like macros defined by the Standard C library and described in this clause as expanding to integral constant expressions are also suitable for use in #if preprocessing directives, unless explicitly stated otherwise.

The C++ wording does not specify the C99 Standard and some implementations may only support the requirements specified in C90.

all floating values shall be constant expressions.

346

C90

 

all other values need not be constant expressions.

This specification has become more restrictive, from the implementations point of view, in C99.

C++

It is possible that some implementations will only meet the requirements contained in the C90 Standard.

v 1.0b

September 2, 2005

Соседние файлы в предмете Электротехника