Programming languages — C (INTERNATIONAL STANDARD ISO/IEC 9899:TC3) - page 3

 

  Главная      Manuals     Programming languages — C (INTERNATIONAL STANDARD ISO/IEC 9899:TC3) - 2007 year

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     1      2      3      4      ..

 

 

 

Programming languages — C (INTERNATIONAL STANDARD ISO/IEC 9899:TC3) - page 3

 

 

7.24.6.4.2 The

wcsrtombs

function

Synopsis

1

#include <wchar.h>

size_t wcsrtombs(char * restrict dst,

const wchar_t ** restrict src,

size_t len,

mbstate_t * restrict ps);

Description

2

The

wcsrtombs

function converts a sequence of wide characters from the array

indirectly pointed to by

src

into a sequence of corresponding multibyte characters that

begins in the conversion state described by the object pointed to by

ps

. If

dst

is not a

null pointer, the converted characters are then stored into the array pointed to by

dst

.

Conversion continues up to and including a terminating null wide character, which is also
stored. Conversion stops earlier in two cases: when a wide character is reached that does
not correspond to a valid multibyte character, or (if

dst

is not a null pointer) when the

next multibyte character would exceed the limit of

len

total bytes to be stored into the

array pointed to by

dst

. Each conversion takes place as if by a call to the

wcrtomb

function.

302)

3

If

dst

is not a null pointer, the pointer object pointed to by

src

is assigned either a null

pointer (if conversion stopped due to reaching a terminating null wide character) or the
address just past the last wide character converted (if any). If conversion stopped due to
reaching a terminating null wide character, the resulting state described is the initial
conversion state.

Returns

4

If conversion stops because a wide character is reached that does not correspond to a
valid multibyte character, an encoding error occurs: the

wcsrtombs

function stores the

value of the macro

EILSEQ

in

errno

and returns

(size_t)(-1)

; the conversion

state is unspecified. Otherwise, it returns the number of bytes in the resulting multibyte
character sequence, not including the terminating null character (if any).

302) If conversion stops because a terminating null wide character has been reached, the bytes stored

include those necessary to reach the initial shift state immediately before the null byte.

392 Library

§7.24.6.4.2

-1

indeterminable;

0

evaluate all operations and constants just to the range and precision of the
type;

1

evaluate operations and constants of type

float

and

double

to the

range and precision of the

double

type, evaluate

long double

operations and constants to the range and precision of the

long double

type;

2

evaluate all operations and constants to the range and precision of the

long double

type.

All other negative values for

FLT_EVAL_METHOD

characterize implementation-defined

behavior.

9

The values given in the following list shall be replaced by constant expressions with
implementation-defined values that are greater or equal in magnitude (absolute value) to
those shown, with the same sign:

— radix of exponent representation, b

FLT_RADIX 2

— number of base-

FLT_RADIX

digits in the floating-point significand, p

FLT_MANT_DIG

DBL_MANT_DIG

LDBL_MANT_DIG

— number of decimal digits, n, such that any floating-point number in the widest

supported floating type with p

max

radix digits can be rounded to a floating-point

number with decimal digits and back again without change to the value,

p

max

log

10

b

1

+

p

max

log

10

b

if is a power of 10

otherwise

DECIMAL_DIG 10

— number of decimal digits, q, such that any floating-point number with decimal digits

can be rounded into a floating-point number with radix digits and back again
without change to the decimal digits,

19) The evaluation method determines evaluation formats of expressions involving all floating types, not

just real types. For example, if

FLT_EVAL_METHOD

is 1, then the product of two

float

_Complex

operands is represented in the

double _Complex

format, and its parts are evaluated to

double

.

§5.2.4.2.2 Environment 25

log

10

b

p

1) log

10

b

if is a power of 10

otherwise

FLT_DIG 6

DBL_DIG 10

LDBL_DIG 10

— minimum negative integer such that

FLT_RADIX

raised to one less than that power is

a normalized floating-point number, e

min

FLT_MIN_EXP

DBL_MIN_EXP

LDBL_MIN_EXP

— minimum negative integer such that 10 raised to that power is in the range of

normalized floating-point numbers,

log

10

b

e

min

1

FLT_MIN_10_EXP -37

DBL_MIN_10_EXP -37

LDBL_MIN_10_EXP -37

— maximum integer such that

FLT_RADIX

raised to one less than that power is a

representable finite floating-point number, e

max

FLT_MAX_EXP

DBL_MAX_EXP

LDBL_MAX_EXP

— maximum integer such that 10 raised to that power is in the range of representable

finite floating-point numbers,

log

10

((1

b

p

)b

e

max

)

FLT_MAX_10_EXP +37

DBL_MAX_10_EXP +37

LDBL_MAX_10_EXP +37

10

The values given in the following list shall be replaced by constant expressions with
implementation-defined values that are greater than or equal to those shown:

— maximum representable finite floating-point number, (1

b

p

)b

e

max

FLT_MAX 1E+37

DBL_MAX 1E+37

LDBL_MAX 1E+37

11

The values given in the following list shall be replaced by constant expressions with
implementation-defined (positive) values that are less than or equal to those shown:

— the difference between 1 and the least value greater than 1 that is representable in the

given floating point type, b

1

p

26 Environment §5.2.4.2.2

7.25.2 Wide character classification utilities

1

The header

<wctype.h>

declares several functions useful for classifying wide

characters.

2

The term printing wide character refers to a member of a locale-specific set of wide
characters, each of which occupies at least one printing position on a display device. The
term control wide character refers to a member of a locale-specific set of wide characters
that are not printing wide characters.

7.25.2.1 Wide character classification functions

1

The functions in this subclause return nonzero (true) if and only if the value of the
argument

wc

conforms to that in the description of the function.

2

Each of the following functions returns true for each wide character that corresponds (as
if by a call to the

wctob

function) to a single-byte character for which the corresponding

character classification function from 7.4.1 returns true, except that the

iswgraph

and

iswpunct

functions may differ with respect to wide characters other than

L' '

that are

both printing and white-space wide characters.

304)

Forward references: the

wctob

function (7.24.6.1.2).

7.25.2.1.1 The

iswalnum

function

Synopsis

1

#include <wctype.h>

int iswalnum(wint_t wc);

Description

2

The

iswalnum

function tests for any wide character for which

iswalpha

or

iswdigit

is true.

7.25.2.1.2 The

iswalpha

function

Synopsis

1

#include <wctype.h>

int iswalpha(wint_t wc);

Description

2

The

iswalpha

function tests for any wide character for which

iswupper

or

iswlower

is true, or any wide character that is one of a locale-specific set of alphabetic

304) For example, if the expression

isalpha(wctob(wc))

evaluates to true, then the call

iswalpha(wc)

also returns true. But, if the expression

isgraph(wctob(wc))

evaluates to true

(which cannot occur for

wc == L' '

of course), then either

iswgraph(wc)

or

iswprint(wc)

&& iswspace(wc)

is true, but not both.

394 Library

§7.25.2.1.2

FLT_EPSILON 1E-5

DBL_EPSILON 1E-9

LDBL_EPSILON 1E-9

— minimum normalized positive floating-point number, b

e

min

1

FLT_MIN 1E-37

DBL_MIN 1E-37

LDBL_MIN 1E-37

Recommended practice

12

Conversion from (at least)

double

to decimal with

DECIMAL_DIG

digits and back

should be the identity function.

13

EXAMPLE 1

The following describes an artificial floating-point representation that meets the minimum

requirements of this International Standard, and the appropriate values in a

<float.h>

header for type

float

:

x

=

s16

e

6

k

=

1

Σ

f

k

16

k

,

31

e

≤ +

32

FLT_RADIX 16

FLT_MANT_DIG 6

FLT_EPSILON 9.53674316E-07F

FLT_DIG 6

FLT_MIN_EXP -31

FLT_MIN 2.93873588E-39F

FLT_MIN_10_EXP -38

FLT_MAX_EXP +32

FLT_MAX 3.40282347E+38F

FLT_MAX_10_EXP +38

14

EXAMPLE 2

The following describes floating-point representations that also meet the requirements for

single-precision and double-precision normalized numbers in IEC 60559,

20)

and the appropriate values in a

<float.h>

header for types

float

and

double

:

x

f

=

s2

e

24

k

=

1

Σ

f

k

2

k

,

125

e

≤ +

128

x

d

=

s2

e

53

k

=

1

Σ

f

k

2

k

,

1021

e

≤ +

1024

FLT_RADIX 2

DECIMAL_DIG 17

FLT_MANT_DIG 24

FLT_EPSILON 1.19209290E-07F //

decimal constant

FLT_EPSILON 0X1P-23F //

hex constant

20) The floating-point model in that standard sums powers of from zero, so the values of the exponent

limits are one less than shown here.

§5.2.4.2.2 Environment 27

FLT_DIG 6

FLT_MIN_EXP -125

FLT_MIN 1.17549435E-38F //

decimal constant

FLT_MIN 0X1P-126F //

hex constant

FLT_MIN_10_EXP -37

FLT_MAX_EXP +128

FLT_MAX 3.40282347E+38F //

decimal constant

FLT_MAX 0X1.fffffeP127F //

hex constant

FLT_MAX_10_EXP +38

DBL_MANT_DIG 53

DBL_EPSILON 2.2204460492503131E-16 //

decimal constant

DBL_EPSILON 0X1P-52 //

hex constant

DBL_DIG 15

DBL_MIN_EXP -1021

DBL_MIN 2.2250738585072014E-308 //

decimal constant

DBL_MIN 0X1P-1022 //

hex constant

DBL_MIN_10_EXP -307

DBL_MAX_EXP +1024

DBL_MAX 1.7976931348623157E+308 //

decimal constant

DBL_MAX 0X1.fffffffffffffP1023 //

hex constant

DBL_MAX_10_EXP +308

If a type wider than

double

were supported, then

DECIMAL_DIG

would be greater than 17. For

example, if the widest type were to use the minimal-width IEC 60559 double-extended format (64 bits of
precision), then

DECIMAL_DIG

would be 21.

Forward references:

conditional inclusion (6.10.1), complex

arithmetic

<complex.h>

(7.3), extended multibyte and wide character utilities

<wchar.h>

(7.24), floating-point environment

<fenv.h>

(7.6), general utilities

<stdlib.h>

(7.20), input/output

<stdio.h>

(7.19), mathematics

<math.h>

(7.12).

28 Environment §5.2.4.2.2

6. Language

6.1 Notation

1

In the syntax notation used in this clause, syntactic categories (nonterminals) are
indicated by italic type, and literal words and character set members (terminals) by

bold

type

. A colon (:) following a nonterminal introduces its definition. Alternative

definitions are listed on separate lines, except when prefaced by the words ‘‘one of’’. An
optional symbol is indicated by the subscript ‘‘opt’’, so that

{

expression

opt

}

indicates an optional expression enclosed in braces.

2

When syntactic categories are referred to in the main text, they are not italicized and
words are separated by spaces instead of hyphens.

3

A summary of the language syntax is given in annex A.

6.2 Concepts

6.2.1 Scopes of identifiers

1

An identifier can denote an object; a function; a tag or a member of a structure, union, or
enumeration; a typedef name; a label name; a macro name; or a macro parameter. The
same identifier can denote different entities at different points in the program. A member
of an enumeration is called an enumeration constant. Macro names and macro
parameters are not considered further here, because prior to the semantic phase of
program translation any occurrences of macro names in the source file are replaced by the
preprocessing token sequences that constitute their macro definitions.

2

For each different entity that an identifier designates, the identifier is visible (i.e., can be
used) only within a region of program text called its scope. Different entities designated
by the same identifier either have different scopes, or are in different name spaces. There
are four kinds of scopes: function, file, block, and function prototype. (A function
prototype 
is a declaration of a function that declares the types of its parameters.)

3

A label name is the only kind of identifier that has function scope. It can be used (in a

goto

statement) anywhere in the function in which it appears, and is declared implicitly

by its syntactic appearance (followed by a

:

and a statement).

4

Every other identifier has scope determined by the placement of its declaration (in a
declarator or type specifier). If the declarator or type specifier that declares the identifier
appears outside of any block or list of parameters, the identifier has file scope, which
terminates at the end of the translation unit. If the declarator or type specifier that
declares the identifier appears inside a block or within the list of parameter declarations in
a function definition, the identifier has block scope, which terminates at the end of the
associated block. If the declarator or type specifier that declares the identifier appears

§6.2.1 Language

29

within the list of parameter declarations in a function prototype (not part of a function
definition), the identifier has function prototype scope, which terminates at the end of the
function declarator. If an identifier designates two different entities in the same name
space, the scopes might overlap. If so, the scope of one entity (the inner scope) will be a
strict subset of the scope of the other entity (the outer scope). Within the inner scope, the
identifier designates the entity declared in the inner scope; the entity declared in the outer
scope is hidden (and not visible) within the inner scope.

5

Unless explicitly stated otherwise, where this International Standard uses the term
‘‘identifier’’ to refer to some entity (as opposed to the syntactic construct), it refers to the
entity in the relevant name space whose declaration is visible at the point the identifier
occurs.

6

Tw o identifiers have the same scope if and only if their scopes terminate at the same
point.

7

Structure, union, and enumeration tags have scope that begins just after the appearance of
the tag in a type specifier that declares the tag. Each enumeration constant has scope that
begins just after the appearance of its defining enumerator in an enumerator list. Any
other identifier has scope that begins just after the completion of its declarator.

Forward references: declarations (6.7), function calls (6.5.2.2), function definitions
(6.9.1), identifiers (6.4.2), name spaces of identifiers (6.2.3), macro replacement (6.10.3),
source file inclusion (6.10.2), statements (6.8).

6.2.2 Linkages of identifiers

1

An identifier declared in different scopes or in the same scope more than once can be
made to refer to the same object or function by a process called linkage.

21)

There are

three kinds of linkage: external, internal, and none.

2

In the set of translation units and libraries that constitutes an entire program, each
declaration of a particular identifier with external linkage denotes the same object or
function. Within one translation unit, each declaration of an identifier with internal
linkage 
denotes the same object or function. Each declaration of an identifier with no
linkage 
denotes a unique entity.

3

If the declaration of a file scope identifier for an object or a function contains the storage-
class specifier

static

, the identifier has internal linkage.

22)

4

For an identifier declared with the storage-class specifier

extern

in a scope in which a

21) There is no linkage between different identifiers.

22) A function declaration can contain the storage-class specifier

static

only if it is at file scope; see

6.7.1.

30 Language

§6.2.2

prior declaration of that identifier is visible,

23)

if the prior declaration specifies internal or

external linkage, the linkage of the identifier at the later declaration is the same as the
linkage specified at the prior declaration. If no prior declaration is visible, or if the prior
declaration specifies no linkage, then the identifier has external linkage.

5

If the declaration of an identifier for a function has no storage-class specifier, its linkage
is determined exactly as if it were declared with the storage-class specifier

extern

. If

the declaration of an identifier for an object has file scope and no storage-class specifier,
its linkage is external.

6

The following identifiers have no linkage: an identifier declared to be anything other than
an object or a function; an identifier declared to be a function parameter; a block scope
identifier for an object declared without the storage-class specifier

extern

.

7

If, within a translation unit, the same identifier appears with both internal and external
linkage, the behavior is undefined.

Forward references: declarations (6.7), expressions (6.5), external definitions (6.9),
statements (6.8).

6.2.3 Name spaces of identifiers

1

If more than one declaration of a particular identifier is visible at any point in a
translation unit, the syntactic context disambiguates uses that refer to different entities.
Thus, there are separate name spaces for various categories of identifiers, as follows:

— label names (disambiguated by the syntax of the label declaration and use);

— the tags of structures, unions, and enumerations (disambiguated by following any

24)

of the keywords

struct

,

union

, or

enum

);

— the members of structures or unions; each structure or union has a separate name

space for its members (disambiguated by the type of the expression used to access the
member via the

.

or

->

operator);

— all other identifiers, called ordinary identifiers (declared in ordinary declarators or as

enumeration constants).

Forward references:

enumeration specifiers (6.7.2.2), labeled statements (6.8.1),

structure and union specifiers (6.7.2.1), structure and union members (6.5.2.3), tags
(6.7.2.3), the

goto

statement (6.8.6.1).

23) As specified in 6.2.1, the later declaration might hide the prior declaration.

24) There is only one name space for tags even though three are possible.

§6.2.3 Language

31

6.2.4 Storage durations of objects

1

An object has a storage duration that determines its lifetime. There are three storage
durations: static, automatic, and allocated. Allocated storage is described in 7.20.3.

2

The lifetime of an object is the portion of program execution during which storage is
guaranteed to be reserved for it. An object exists, has a constant address,

25)

and retains

its last-stored value throughout its lifetime.

26)

If an object is referred to outside of its

lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when
the object it points to reaches the end of its lifetime.

3

An object whose identifier is declared with external or internal linkage, or with the
storage-class specifier

static

has static storage duration. Its lifetime is the entire

execution of the program and its stored value is initialized only once, prior to program
startup.

4

An object whose identifier is declared with no linkage and without the storage-class
specifier

static

has automatic storage duration.

5

For such an object that does not have a variable length array type, its lifetime extends
from entry into the block with which it is associated until execution of that block ends in
any way. (Entering an enclosed block or calling a function suspends, but does not end,
execution of the current block.) If the block is entered recursively, a new instance of the
object is created each time. The initial value of the object is indeterminate. If an
initialization is specified for the object, it is performed each time the declaration is
reached in the execution of the block; otherwise, the value becomes indeterminate each
time the declaration is reached.

6

For such an object that does have a variable length array type, its lifetime extends from
the declaration of the object until execution of the program leaves the scope of the
declaration.

27)

If the scope is entered recursively, a new instance of the object is created

each time. The initial value of the object is indeterminate.

Forward references: statements (6.8), function calls (6.5.2.2), declarators (6.7.5), array
declarators (6.7.5.2), initialization (6.7.8).

25) The term ‘‘constant address’’ means that two pointers to the object constructed at possibly different

times will compare equal. The address may be different during two different executions of the same
program.

26) In the case of a volatile object, the last store need not be explicit in the program.

27) Leaving the innermost block containing the declaration, or jumping to a point in that block or an

embedded block prior to the declaration, leaves the scope of the declaration.

32 Language

§6.2.4

6.2.5 Types

1

The meaning of a value stored in an object or returned by a function is determined by the
type of the expression used to access it. (An identifier declared to be an object is the
simplest such expression; the type is specified in the declaration of the identifier.) Types
are partitioned into object types (types that fully describe objects), function types (types
that describe functions), and incomplete types (types that describe objects but lack
information needed to determine their sizes).

2

An object declared as type

_Bool

is large enough to store the values 0 and 1.

3

An object declared as type

char

is large enough to store any member of the basic

execution character set. If a member of the basic execution character set is stored in a

char

object, its value is guaranteed to be nonnegative. If any other character is stored in

a

char

object, the resulting value is implementation-defined but shall be within the range

of values that can be represented in that type.

4

There are five standard signed integer types, designated as

signed char

,

short

int

,

int

,

long int

, and

long long int

. (These and other types may be

designated in several additional ways, as described in 6.7.2.) There may also be
implementation-defined extended signed integer types.

28)

The standard and extended

signed integer types are collectively called signed integer types.

29)

5

An object declared as type

signed char

occupies the same amount of storage as a

‘‘plain’’

char

object. A ‘‘plain’’

int

object has the natural size suggested by the

architecture of the execution environment (large enough to contain any value in the range

INT_MIN

to

INT_MAX

as defined in the header

<limits.h>

).

6

For each of the signed integer types, there is a corresponding (but different) unsigned
integer type (designated with the keyword

unsigned

) that uses the same amount of

storage (including sign information) and has the same alignment requirements. The type

_Bool

and the unsigned integer types that correspond to the standard signed integer

types are the standard unsigned integer types.

The unsigned integer types that

correspond to the extended signed integer types are the extended unsigned integer types.
The standard and extended unsigned integer types are collectively called unsigned integer
types
.

30)

28) Implementation-defined keywords shall have the form of an identifier reserved for any use as

described in 7.1.3.

29) Therefore, any statement in this Standard about signed integer types also applies to the extended

signed integer types.

30) Therefore, any statement in this Standard about unsigned integer types also applies to the extended

unsigned integer types.

§6.2.5 Language

33

7

The standard signed integer types and standard unsigned integer types are collectively
called the standard integer types, the extended signed integer types and extended
unsigned integer types are collectively called the extended integer types.

8

For any two integer types with the same signedness and different integer conversion rank
(see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a
subrange of the values of the other type.

9

The range of nonnegative values of a signed integer type is a subrange of the
corresponding unsigned integer type, and the representation of the same value in each
type is the same.

31)

A computation involving unsigned operands can never overflow,

because a result that cannot be represented by the resulting unsigned integer type is
reduced modulo the number that is one greater than the largest value that can be
represented by the resulting type.

10

There are three real floating types, designated as

float

,

double

, and

long

double

.

32)

The set of values of the type

float

is a subset of the set of values of the

type

double

; the set of values of the type

double

is a subset of the set of values of the

type

long double

.

11

There are three complex types, designated as

float _Complex

,

double

_Complex

, and

long double _Complex

.

33)

The real floating and complex types

are collectively called the floating types.

12

For each floating type there is a corresponding real type, which is always a real floating
type. For real floating types, it is the same type. For complex types, it is the type given
by deleting the keyword

_Complex

from the type name.

13

Each complex type has the same representation and alignment requirements as an array
type containing exactly two elements of the corresponding real type; the first element is
equal to the real part, and the second element to the imaginary part, of the complex
number.

14

The type

char

, the signed and unsigned integer types, and the floating types are

collectively called the basic types. Even if the implementation defines two or more basic
types to have the same representation, they are nevertheless different types.

34)

31) The same representation and alignment requirements are meant to imply interchangeability as

arguments to functions, return values from functions, and members of unions.

32) See ‘‘future language directions’’ (6.11.1).

33) A specification for imaginary types is in informative annex G.

34) An implementation may define new keywords that provide alternative ways to designate a basic (or

any other) type; this does not violate the requirement that all basic types be different.
Implementation-defined keywords shall have the form of an identifier reserved for any use as
described in 7.1.3.

34 Language

§6.2.5

15

The three types

char

,

signed char

, and

unsigned char

are collectively called

the character types. The implementation shall define

char

to have the same range,

representation, and behavior as either

signed char

or

unsigned char

.

35)

16

An enumeration comprises a set of named integer constant values. Each distinct
enumeration constitutes a different enumerated type.

17

The type

char

, the signed and unsigned integer types, and the enumerated types are

collectively called integer types. The integer and real floating types are collectively called
real types.

18

Integer and floating types are collectively called arithmetic types. Each arithmetic type
belongs to one type domain: the real type domain comprises the real types, the complex
type domain 
comprises the complex types.

19

The

void

type comprises an empty set of values; it is an incomplete type that cannot be

completed.

20

Any number of derived types can be constructed from the object, function, and
incomplete types, as follows:

— An array type describes a contiguously allocated nonempty set of objects with a

particular member object type, called the element type.

36)

Array types are

characterized by their element type and by the number of elements in the array. An
array type is said to be derived from its element type, and if its element type is , the
array type is sometimes called ‘‘array of ’’. The construction of an array type from
an element type is called ‘‘array type derivation’’.

— A structure type describes a sequentially allocated nonempty set of member objects

(and, in certain circumstances, an incomplete array), each of which has an optionally
specified name and possibly distinct type.

— A union type describes an overlapping nonempty set of member objects, each of

which has an optionally specified name and possibly distinct type.

— A function type describes a function with specified return type. A function type is

characterized by its return type and the number and types of its parameters. A
function type is said to be derived from its return type, and if its return type is , the
function type is sometimes called ‘‘function returning ’’. The construction of a
function type from a return type is called ‘‘function type derivation’’.

35)

CHAR_MIN

, defined in

<limits.h>

, will have one of the values 0 or

SCHAR_MIN

, and this can be

used to distinguish the two options. Irrespective of the choice made,

char

is a separate type from the

other two and is not compatible with either.

36) Since object types do not include incomplete types, an array of incomplete type cannot be constructed.

§6.2.5 Language

35

— A pointer type may be derived from a function type, an object type, or an incomplete

type, called the referenced type. A pointer type describes an object whose value
provides a reference to an entity of the referenced type. A pointer type derived from
the referenced type is sometimes called ‘‘pointer to ’’. The construction of a
pointer type from a referenced type is called ‘‘pointer type derivation’’.

These methods of constructing derived types can be applied recursively.

21

Arithmetic types and pointer types are collectively called scalar types. Array and
structure types are collectively called aggregate types.

37)

22

An array type of unknown size is an incomplete type. It is completed, for an identifier of
that type, by specifying the size in a later declaration (with internal or external linkage).
A structure or union type of unknown content (as described in 6.7.2.3) is an incomplete
type. It is completed, for all declarations of that type, by declaring the same structure or
union tag with its defining content later in the same scope.

23

A type has known constant size if the type is not incomplete and is not a variable length
array type.

24

Array, function, and pointer types are collectively called derived declarator types. A
declarator type derivation from a type is the construction of a derived declarator type
from by the application of an array-type, a function-type, or a pointer-type derivation to
.

25

A type is characterized by its type category, which is either the outermost derivation of a
derived type (as noted above in the construction of derived types), or the type itself if the
type consists of no derived types.

26

Any type so far mentioned is an unqualified type. Each unqualified type has several
qualified versions of its type,

38)

corresponding to the combinations of one, two, or all

three of the

const

,

volatile

, and

restrict

qualifiers. The qualified or unqualified

versions of a type are distinct types that belong to the same type category and have the
same representation and alignment requirements.

39)

A derived type is not qualified by the

qualifiers (if any) of the type from which it is derived.

27

A pointer to

void

shall have the same representation and alignment requirements as a

pointer to a character type.

39)

Similarly, pointers to qualified or unqualified versions of

compatible types shall have the same representation and alignment requirements. All

37) Note that aggregate type does not include union type because an object with union type can only

contain one member at a time.

38) See 6.7.3 regarding qualified array and function types.

39) The same representation and alignment requirements are meant to imply interchangeability as

arguments to functions, return values from functions, and members of unions.

36 Language

§6.2.5

7.24.6.1 Single-byte/wide character conversion functions

7.24.6.1.1 The

btowc

function

Synopsis

1

#include <stdio.h>

#include <wchar.h>

wint_t btowc(int c);

Description

2

The

btowc

function determines whether

c

constitutes a valid single-byte character in the

initial shift state.

Returns

3

The

btowc

function returns

WEOF

if

c

has the value

EOF

or if

(unsigned char)c

does not constitute a valid single-byte character in the initial shift state. Otherwise, it
returns the wide character representation of that character.

7.24.6.1.2 The

wctob

function

Synopsis

1

#include <stdio.h>

#include <wchar.h>

int wctob(wint_t c);

Description

2

The

wctob

function determines whether

c

corresponds to a member of the extended

character set whose multibyte character representation is a single byte when in the initial
shift state.

Returns

3

The

wctob

function returns

EOF

if

c

does not correspond to a multibyte character with

length one in the initial shift state. Otherwise, it returns the single-byte representation of
that character as an

unsigned char

converted to an

int

.

7.24.6.2 Conversion state functions

7.24.6.2.1 The

mbsinit

function

Synopsis

1

#include <wchar.h>

int mbsinit(const mbstate_t *ps);

Description

2

If

ps

is not a null pointer, the

mbsinit

function determines whether the pointed-to

mbstate_t

object describes an initial conversion state.

§7.24.6.2.1 Library

387

pointers to structure types shall have the same representation and alignment requirements
as each other. All pointers to union types shall have the same representation and
alignment requirements as each other. Pointers to other types need not have the same
representation or alignment requirements.

28

EXAMPLE 1

The type designated as ‘‘

float *

’’ has type ‘‘pointer to

float

’’. Its type category is

pointer, not a floating type. The const-qualified version of this type is designated as ‘‘

float * const

’’

whereas the type designated as ‘‘

const float *

’’ is not a qualified type — its type is ‘‘pointer to const-

qualified

float

’’ and is a pointer to a qualified type.

29

EXAMPLE 2

The type designated as ‘‘

struct tag (*[5])(float)

’’ has type ‘‘array of pointer to

function returning

struct tag

’’. The array has length five and the function has a single parameter of type

float

. Its type category is array.

Forward references: compatible type and composite type (6.2.7), declarations (6.7).

6.2.6 Representations of types

6.2.6.1 General

1

The representations of all types are unspecified except as stated in this subclause.

2

Except for bit-fields, objects are composed of contiguous sequences of one or more bytes,
the number, order, and encoding of which are either explicitly specified or
implementation-defined.

3

Values stored in unsigned bit-fields and objects of type

unsigned char

shall be

represented using a pure binary notation.

40)

4

Values stored in non-bit-field objects of any other object type consist of n

×

CHAR_BIT

bits, where is the size of an object of that type, in bytes. The value may be copied into
an object of type

unsigned char [

n

]

(e.g., by

memcpy

); the resulting set of bytes is

called the object representation of the value. Values stored in bit-fields consist of bits,
where is the size specified for the bit-field. The object representation is the set of m
bits the bit-field comprises in the addressable storage unit holding it. Tw o values (other
than NaNs) with the same object representation compare equal, but values that compare
equal may have different object representations.

5

Certain object representations need not represent a value of the object type. If the stored
value of an object has such a representation and is read by an lvalue expression that does
not have character type, the behavior is undefined. If such a representation is produced
by a side effect that modifies all or any part of the object by an lvalue expression that
does not have character type, the behavior is undefined.

41)

Such a representation is called

40) A positional representation for integers that uses the binary digits 0 and 1, in which the values

represented by successive bits are additive, begin with 1, and are multiplied by successive integral
powers of 2, except perhaps the bit with the highest position. (Adapted from the American National
Dictionary for Information Processing Systems
.) A byte contains

CHAR_BIT

bits, and the values of

type

unsigned char

range from 0 to

2

CHAR_BIT

1

.

§6.2.6.1 Language

37

trap representation.

6

When a value is stored in an object of structure or union type, including in a member
object, the bytes of the object representation that correspond to any padding bytes take
unspecified values.

42)

The value of a structure or union object is never a trap

representation, even though the value of a member of the structure or union object may be
a trap representation.

7

When a value is stored in a member of an object of union type, the bytes of the object
representation that do not correspond to that member but do correspond to other members
take unspecified values.

8

Where an operator is applied to a value that has more than one object representation,
which object representation is used shall not affect the value of the result.

43)

Where a

value is stored in an object using a type that has more than one object representation for
that value, it is unspecified which representation is used, but a trap representation shall
not be generated.

Forward references: declarations (6.7), expressions (6.5), lvalues, arrays, and function
designators (6.3.2.1).

6.2.6.2 Integer types

1

For unsigned integer types other than

unsigned char

, the bits of the object

representation shall be divided into two groups: value bits and padding bits (there need
not be any of the latter). If there are value bits, each bit shall represent a different
power of 2 between 1 and 2

N

1

, so that objects of that type shall be capable of

representing values from 0 to 2

N

1 using a pure binary representation; this shall be

known as the value representation. The values of any padding bits are unspecified.

44)

2

For signed integer types, the bits of the object representation shall be divided into three
groups: value bits, padding bits, and the sign bit. There need not be any padding bits;

41) Thus, an automatic variable can be initialized to a trap representation without causing undefined

behavior, but the value of the variable cannot be used until a proper value is stored in it.

42) Thus, for example, structure assignment need not copy any padding bits.

43) It is possible for objects

x

and

y

with the same effective type

T

to have the same value when they are

accessed as objects of type

T

, but to have different values in other contexts. In particular, if

==

is

defined for type

T

, then

x == y

does not imply that

memcmp(&x, &y, sizeof (T)) == 0

.

Furthermore,

x == y

does not necessarily imply that

x

and

y

have the same value; other operations

on values of type

T

may distinguish between them.

44) Some combinations of padding bits might generate trap representations, for example, if one padding

bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
representation other than as part of an exceptional condition such as an overflow, and this cannot occur
with unsigned types. All other combinations of padding bits are alternative object representations of
the value specified by the value bits.

38 Language

§6.2.6.2

there shall be exactly one sign bit. Each bit that is a value bit shall have the same value as
the same bit in the object representation of the corresponding unsigned type (if there are

value bits in the signed type and in the unsigned type, then M

). If the sign bit

is zero, it shall not affect the resulting value. If the sign bit is one, the value shall be
modified in one of the following ways:

— the corresponding value with sign bit 0 is negated (sign and magnitude);

— the sign bit has the value

(2

N

) (two’s complement);

— the sign bit has the value

(2

N

1) (ones’ complement).

Which of these applies is implementation-defined, as is whether the value with sign bit 1
and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones’
complement), is a trap representation or a normal value. In the case of sign and
magnitude and ones’ complement, if this representation is a normal value it is called a
negative zero.

3

If the implementation supports negative zeros, they shall be generated only by:

— the

&

,

|

,

^

,

~

,

<<

, and

>>

operators with arguments that produce such a value;

— the

+

,

-

,

*

,

/

, and

%

operators where one argument is a negative zero and the result is

zero;

— compound assignment operators based on the above cases.

It is unspecified whether these cases actually generate a negative zero or a normal zero,
and whether a negative zero becomes a normal zero when stored in an object.

4

If the implementation does not support negative zeros, the behavior of the

&

,

|

,

^

,

~

,

<<

,

and

>>

operators with arguments that would produce such a value is undefined.

5

The values of any padding bits are unspecified.

45)

A valid (non-trap) object representation

of a signed integer type where the sign bit is zero is a valid object representation of the
corresponding unsigned type, and shall represent the same value. For any integer type,
the object representation where all the bits are zero shall be a representation of the value
zero in that type.

6

The precision of an integer type is the number of bits it uses to represent values,
excluding any sign and padding bits. The width of an integer type is the same but
including any sign bit; thus for unsigned integer types the two values are the same, while

45) Some combinations of padding bits might generate trap representations, for example, if one padding

bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
representation other than as part of an exceptional condition such as an overflow. All other
combinations of padding bits are alternative object representations of the value specified by the value
bits.

§6.2.6.2 Language

39

for signed integer types the width is one greater than the precision.

6.2.7 Compatible type and composite type

1

Tw o types have compatible type if their types are the same. Additional rules for
determining whether two types are compatible are described in 6.7.2 for type specifiers,
in 6.7.3 for type qualifiers, and in 6.7.5 for declarators.

46)

Moreover, two structure,

union, or enumerated types declared in separate translation units are compatible if their
tags and members satisfy the following requirements: If one is declared with a tag, the
other shall be declared with the same tag. If both are complete types, then the following
additional requirements apply: there shall be a one-to-one correspondence between their
members such that each pair of corresponding members are declared with compatible
types, and such that if one member of a corresponding pair is declared with a name, the
other member is declared with the same name. For two structures, corresponding
members shall be declared in the same order. For two structures or unions, corresponding
bit-fields shall have the same widths. For two enumerations, corresponding members
shall have the same values.

2

All declarations that refer to the same object or function shall have compatible type;
otherwise, the behavior is undefined.

3

composite type can be constructed from two types that are compatible; it is a type that
is compatible with both of the two types and satisfies the following conditions:

— If one type is an array of known constant size, the composite type is an array of that

size; otherwise, if one type is a variable length array, the composite type is that type.

— If only one type is a function type with a parameter type list (a function prototype),

the composite type is a function prototype with the parameter type list.

— If both types are function types with parameter type lists, the type of each parameter

in the composite parameter type list is the composite type of the corresponding
parameters.

These rules apply recursively to the types from which the two types are derived.

4

For an identifier with internal or external linkage declared in a scope in which a prior
declaration of that identifier is visible,

47)

if the prior declaration specifies internal or

external linkage, the type of the identifier at the later declaration becomes the composite
type.

46) Tw o types need not be identical to be compatible.

47) As specified in 6.2.1, the later declaration might hide the prior declaration.

40 Language

§6.2.7

5

EXAMPLE Given the following two file scope declarations:

int f(int (*)(), double (*)[3]);

int f(int (*)(char *), double (*)[]);

The resulting composite type for the function is:

int f(int (*)(char *), double (*)[3]);

§6.2.7 Language

41

6.3 Conversions

1

Several operators convert operand values from one type to another automatically. This
subclause specifies the result required from such an implicit conversion, as well as those
that result from a cast operation (an explicit conversion). The list in 6.3.1.8 summarizes
the conversions performed by most ordinary operators; it is supplemented as required by
the discussion of each operator in 6.5.

2

Conversion of an operand value to a compatible type causes no change to the value or the
representation.

Forward references: cast operators (6.5.4).

6.3.1 Arithmetic operands

6.3.1.1 Boolean, characters, and integers

1

Every integer type has an integer conversion rank defined as follows:

— No two signed integer types shall have the same rank, even if they hav e the same

representation.

— The rank of a signed integer type shall be greater than the rank of any signed integer

type with less precision.

— The rank of

long long int

shall be greater than the rank of

long int

, which

shall be greater than the rank of

int

, which shall be greater than the rank of

short

int

, which shall be greater than the rank of

signed char

.

— The rank of any unsigned integer type shall equal the rank of the corresponding

signed integer type, if any.

— The rank of any standard integer type shall be greater than the rank of any extended

integer type with the same width.

— The rank of

char

shall equal the rank of

signed char

and

unsigned char

.

— The rank of

_Bool

shall be less than the rank of all other standard integer types.

— The rank of any enumerated type shall equal the rank of the compatible integer type

(see 6.7.2.2).

— The rank of any extended signed integer type relative to another extended signed

integer type with the same precision is implementation-defined, but still subject to the
other rules for determining the integer conversion rank.

— For all integer types

T1

,

T2

, and

T3

, if

T1

has greater rank than

T2

and

T2

has

greater rank than

T3

, then

T1

has greater rank than

T3

.

2

The following may be used in an expression wherever an

int

or

unsigned int

may

be used:

42 Language

§6.3.1.1

— An object or expression with an integer type whose integer conversion rank is less

than or equal to the rank of

int

and

unsigned int

.

— A bit-field of type

_Bool

,

int

,

signed int

, or

unsigned int

.

If an

int

can represent all values of the original type, the value is converted to an

int

;

otherwise, it is converted to an

unsigned int

. These are called the integer

promotions.

48)

All other types are unchanged by the integer promotions.

3

The integer promotions preserve value including sign. As discussed earlier, whether a
‘‘plain’’

char

is treated as signed is implementation-defined.

Forward references: enumeration specifiers (6.7.2.2), structure and union specifiers
(6.7.2.1).

6.3.1.2 Boolean type

1

When any scalar value is converted to

_Bool

, the result is 0 if the value compares equal

to 0; otherwise, the result is 1.

6.3.1.3 Signed and unsigned integers

1

When a value with integer type is converted to another integer type other than

_Bool

, if

the value can be represented by the new type, it is unchanged.

2

Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
subtracting one more than the maximum value that can be represented in the new type
until the value is in the range of the new type.

49)

3

Otherwise, the new type is signed and the value cannot be represented in it; either the
result is implementation-defined or an implementation-defined signal is raised.

6.3.1.4 Real floating and integer

1

When a finite value of real floating type is converted to an integer type other than

_Bool

,

the fractional part is discarded (i.e., the value is truncated toward zero). If the value of
the integral part cannot be represented by the integer type, the behavior is undefined.

50)

2

When a value of integer type is converted to a real floating type, if the value being
converted can be represented exactly in the new type, it is unchanged. If the value being
converted is in the range of values that can be represented but cannot be represented

48) The integer promotions are applied only: as part of the usual arithmetic conversions, to certain

argument expressions, to the operands of the unary

+

,

-

, and

~

operators, and to both operands of the

shift operators, as specified by their respective subclauses.

49) The rules describe arithmetic on the mathematical value, not the value of a given type of expression.

50) The remaindering operation performed when a value of integer type is converted to unsigned type

need not be performed when a value of real floating type is converted to unsigned type. Thus, the
range of portable real floating values is (−1,

U

type

_MAX

+1).

§6.3.1.4 Language

43

exactly, the result is either the nearest higher or nearest lower representable value, chosen
in an implementation-defined manner. If the value being converted is outside the range of
values that can be represented, the behavior is undefined.

6.3.1.5 Real floating types

1

When a

float

is promoted to

double

or

long double

, or a

double

is promoted

to

long double

, its value is unchanged (if the source value is represented in the

precision and range of its type).

2

When a

double

is demoted to

float

, a

long double

is demoted to

double

or

float

, or a value being represented in greater precision and range than required by its

semantic type (see 6.3.1.8) is explicitly converted (including to its own type), if the value
being converted can be represented exactly in the new type, it is unchanged. If the value
being converted is in the range of values that can be represented but cannot be
represented exactly, the result is either the nearest higher or nearest lower representable
value, chosen in an implementation-defined manner. If the value being converted is
outside the range of values that can be represented, the behavior is undefined.

6.3.1.6 Complex types

1

When a value of complex type is converted to another complex type, both the real and
imaginary parts follow the conversion rules for the corresponding real types.

6.3.1.7 Real and complex

1

When a value of real type is converted to a complex type, the real part of the complex
result value is determined by the rules of conversion to the corresponding real type and
the imaginary part of the complex result value is a positive zero or an unsigned zero.

2

When a value of complex type is converted to a real type, the imaginary part of the
complex value is discarded and the value of the real part is converted according to the
conversion rules for the corresponding real type.

6.3.1.8 Usual arithmetic conversions

1

Many operators that expect operands of arithmetic type cause conversions and yield result
types in a similar way. The purpose is to determine a common real type for the operands
and result. For the specified operands, each operand is converted, without change of type
domain, to a type whose corresponding real type is the common real type. Unless
explicitly stated otherwise, the common real type is also the corresponding real type of
the result, whose type domain is the type domain of the operands if they are the same,
and complex otherwise. This pattern is called the usual arithmetic conversions:

First, if the corresponding real type of either operand is

long double

, the other

operand is converted, without change of type domain, to a type whose
corresponding real type is

long double

.

44 Language

§6.3.1.8

 

 

 

 

 

 

 

 

Content      ..     1      2      3      4      ..