3. LANGUAGE

   In the syntax notation used in the language section ($3), 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 so that

         {  expression<opt> }

indicates an optional expression enclosed in braces. 

3.1 LEXICAL ELEMENTS

Syntax

          token:

                  keyword

                  identifier

                  constant

                  string-literal

                  operator

                  punctuator

          preprocessing-token:

                  header-name

                  identifier

                  pp-number

                  character-constant

                  string-literal

                  operator

                  punctuator

                  each non-white-space character that cannot be one of the above

Constraints

   Each preprocessing token that is converted to a token shall have the lexical form of a keyword, an identifier, a constant, a string literal, an operator, or a punctuator. 

Semantics

   A token is the minimal lexical element of the language in translation phases 7 and 8.  The categories of tokens are: keywords , identifiers , constants , string literals  ,operators , and punctuators . A preprocessing token is the minimal lexical element of the language in translation phases 3 through 6.  The categories of preprocessing token are: header names  ,identifiers , preprocessing numbers  ,character constants  ,string literals  ,operators , punctuators , and single non-white-space characters that do not lexically match the other preprocessing token categories.  If a ' or a  character matches the last category, the behavior is undefined.  Comments (described later) and the characters space, horizontal tab, new-line, vertical tab, and form-feed---collectively called white space  ---canseparate preprocessing tokens.  As described in $3.8, in certain circumstances during translation phase 4, white space (or the absence thereof) serves as more than preprocessing token separation.  White space may appear within a preprocessing token only as part of a header name or between the quotation characters in a character constant or string literal. 

   If the input stream has been parsed into preprocessing tokens up to a given character, the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token. 

Examples

   The program fragment 1Ex is parsed as a preprocessing number token (one that is not a valid floating or integer constant token), even though a parse as the pair of preprocessing tokens 1 and Ex might produce a valid expression (for example, if Ex were a macro defined as +1 ).  Similarly, the program fragment 1E1 is parsed as a preprocessing number (one that is a valid floating constant token), whether or not E is a macro name. 

   The program fragment x+++++y is parsed as x ++ ++ + y , which violates a constraint on increment operators, even though the parse x ++ + ++ y might yield a correct expression. 

Forward references: character constants ($3.1.3.4), comments ($3.1.9), expressions ($3.3), floating constants ($3.1.3.1), header names ($3.1.7), macro replacement ($3.8.3), postfix increment and decrement operators ($3.3.2.4), prefix increment and decrement operators ($3.3.3.1), preprocessing directives ($3.8), preprocessing numbers ($3.1.8), string literals ($3.1.4). 

3.1.1 Keywords

Syntax

          keyword: one of

         auto     double   int      struct

         break    else     long     switch

         case     enum     register typedef

         char     extern   return   union

         const    float    short    unsigned

         continue for      signed   void

         default  goto     sizeof   volatile

         do       if       static   while

Semantics

   The above tokens (entirely in lower-case) are reserved (in translation phases 7 and 8) for use as keywords, and shall not be used otherwise. 

3.1.2 Identifiers

Syntax

          identifier:

                  nondigit

                  identifier nondigit

                  identifier digit

          nondigit: one of

                  _  a  b  c  d  e  f  g  h  i  j  k  l  m

                     n  o  p  q  r  s  t  u  v  w  x  y  z

                     A  B  C  D  E  F  G  H  I  J  K  L  M

                     N  O  P  Q  R  S  T  U  V  W  X  Y  Z

          digit: one of

                  0  1  2  3  4  5  6  7  8  9

Description

   An identifier is a sequence of nondigit characters (including the underscore _ and the lower-case and upper-case letters) and digits.  The first character shall be a nondigit character. 

Constraints

   In translation phases 7 and 8, an identifier shall not consist of the same sequence of characters as a keyword. 

Semantics

   An identifier denotes an object, a function, or one of the following entities that will be described later: a tag or a member of a structure, union, or enumeration; a typedef name; a label name; a macro name; or a macro parameter.  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. 

   There is no specific limit on the maximum length of an identifier. 

"Implementation limits"

   The implementation shall treat at least the first 31 characters of an internal name (a macro name or an identifier that does not have external linkage) as significant.  Corresponding lower-case and upper-case letters are different.  The implementation may further restrict the significance of an external name (an identifier that has external linkage) to six characters and may ignore distinctions of alphabetical case for such names./10/    These limitations on identifiers are all implementation-defined. 

   Any identifiers that differ in a significant character are different identifiers.  If two identifiers differ in a non-significant character, the behavior is undefined. 

Forward references: linkages of identifiers ($3.1.2.2), macro replacement ($3.8.3). 

3.1.2.1 Scopes of identifiers

   An identifier is visible (i.e., can be used) only within a region of program text called its scope . 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.)

   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).  Label names shall be unique within a function. 

   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 } that closes the associated block.  If the declarator or type specifier that declares the identifier appears 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 outer declaration of a lexically identical identifier exists in the same name space, it is hidden until the current scope terminates, after which it again becomes visible. 

   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: compound statement, or block ($3.6.2), declarations ($3.5), enumeration specifiers ($3.5.2.2), function calls ($3.3.2.2), function declarators (including prototypes) ($3.5.4.3), function definitions ($3.7.1), the goto statement ($3.6.6.1), labeled statements ($3.6.1), name spaces of identifiers ($3.1.2.3), scope of macro definitions ($3.8.3.5), source file inclusion ($3.8.2), tags ($3.5.2.3), type specifiers ($3.5.2). 

3.1.2.2 Linkages of identifiers

   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 . There are three kinds of linkage: external, internal, and none. 

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

   If the declaration of an identifier for an object or a function has file scope and contains the storage-class specifier static , the identifier has internal linkage. 

   If the declaration of an identifier for an object or a function contains the storage-class specifier extern , the identifier has the same linkage as any visible declaration of the identifier with file scope.  If there is no visible declaration with file scope, the identifier has external linkage. 

   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. 

   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; an identifier declared to be an object inside a block without the storage-class specifier extern . 

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

Forward references: compound statement, or block ($3.6.2), declarations ($3.5), expressions ($3.3), external definitions ($3.7). 

3.1.2.3 Name spaces of identifiers

   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/11/ 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: declarators ($3.5.4), enumeration specifiers ($3.5.2.2), labeled statements ($3.6.1), structure and union specifiers ($3.5.2.1), structure and union members ($3.3.2.3), tags ($3.5.2.3). 

3.1.2.4 Storage durations of objects

   An object has a storage duration that determines its lifetime.  There are two storage durations: static and automatic. 

   An object declared with external or internal linkage, or with the storage-class specifier static has static storage duration  .For such an object, storage is reserved and its stored value is initialized only once, prior to program startup.  The object exists and retains its last-stored value throughout the execution of the entire program./12/

   An object declared with no linkage and without the storage-class specifier static has automatic storage duration  .Storage is guaranteed to be reserved for a new instance of such an object on each normal entry into the block in which it is declared, or on a jump from outside the block to a label in the block or in an enclosed block.  If an initialization is specified for the value stored in the object, it is performed on each normal entry, but not if the block is entered by a jump to a label.  Storage for the object is no longer guaranteed to be reserved when execution of the block ends in any way.  (Entering an enclosed block suspends but does not end execution of the enclosing block.  Calling a function that returns suspends but does not end execution of the block containing the call.) The value of a pointer that referred to an object with automatic storage duration that is no longer guaranteed to be reserved is indeterminate. 

Forward references: compound statement, or block ($3.6.2), function calls ($3.3.2.2), initialization ($3.5.7). 

3.1.2.5 Types

   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 describe objects), function types (types that describe functions), and incomplete types (types that describe objects but lack information needed to determine their sizes). 

   An object declared as type char is large enough to store any member of the basic execution character set.  If a member of the required source character set enumerated in $2.2.1 is stored in a char object, its value is guaranteed to be positive.  If other quantities are stored in a char object, the behavior is implementation-defined: the values are treated as either signed  or nonnegative integers. 

   There are four signed integer types  ,designated as signed char , short int , int , and long int .  (The signed integer and other types may be designated in several additional ways, as described in $3.5.2.)

   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> ).  In the list of signed integer types above, the range of values of each type is a subrange of the values of the next type in the list. 

   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 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.  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 unsigned integer type. 

   There are three floating types  ,designated as float , double , and long double .  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 . 

   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. 

   There are three character types  ,designated as char , signed char , and unsigned char . 

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

   The void type comprises an empty set of values; it is an incomplete type that cannot be completed. 

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

 * An array type describes a contiguously allocated set of objects with a particular member object type, called the element type  .Array types are characterized by their element type and by the number of members of the array.  An array type is said to be derived from its element type, and if its element type is T , the array type is sometimes called ``array of T .'' The construction of an array type from an element type is called ``array type derivation.''

 * A structure type describes a sequentially allocated set of member objects, each of which has an optionally specified name and possibly distinct type. 

 * A union type describes an overlapping 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 T , the function type is sometimes called ``function returning T .'' The construction of a function type from a return type is called ``function type derivation.''

 * 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 T is sometimes called ``pointer to T .'' 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. 

   The type char , the signed and unsigned integer types, and the enumerated types are collectively called integral types  .The representations of integral types shall define values by use of a pure binary numeration system./13/    American National Dictionary for Information Processing Systems  .)The representations of floating types are unspecified. 

   Integral and floating types are collectively called arithmetic types  .Arithmetic types and pointer types are collectively called scalar types  .Array and structure types are collectively called aggregate types  ./14/

   A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.  Other pointer types need not have the same representation or alignment requirements. 

   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 $3.5.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. 

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

   A type is characterized by its top type  ,which is either the first type named in describing a derived type (as noted above in the construction of derived types), or the type itself if the type consists of no derived types. 

   A type has qualified type if its top type is specified with a type qualifier; otherwise it has unqualified type  .The type qualifiers const and volatile respectively designate const-qualified type and volatile-qualified type  ./15/   For each qualified type there is an unqualified type that is specified the same way as the qualified type, but without any type qualifiers in its top type.  This type is known as the unqualified version of the qualified type.  Similarly, there are appropriately qualified versions of types (such as a const-qualified version of a type), just as there are appropriately non-qualified versions of types (such as a non-const-qualified version of a type). 

Examples

   The type designated as `` float * '' is called ``pointer to float '' and its top type is a pointer type, 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 --- it is called ``pointer to const float '' and is a pointer to a qualified type. 

   Finally, the type designated as `` struct tag (*[5])(float) '' is called ``array of pointer to function returning struct tag .'' Its top type is array type.  The array has length five and the function has a single parameter of type float . 

Forward references: character constants ($3.1.3.4), declarations ($3.5), tags ($3.5.2.3), type qualifiers ($3.5.3). 

3.1.2.6 Compatible type and composite type

   Two types have compatible type if their types are the same.  Additional rules for determining whether two types are compatible are described in $3.5.2 for type specifiers, in $3.5.3 for type qualifiers, and in $3.5.4 for declarators./16/    Moreover, two structure, union, or enumeration types declared in separate translation units are compatible if they have the same number of members, the same member names, and compatible member types; for two structures, the members shall be in the same order; for two enumerations, the members shall have the same values. 

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

   A 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 has the following additions:

 * If one type is an array of known size, the composite type is an array of that size. 

 * 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 have 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. 

   For an identifier with external or internal linkage declared in the same scope as another declaration for that identifier, the type of the identifier becomes the composite type. 

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]);

Forward references: declarators ($3.5.4), enumeration specifiers ($3.5.2.2), structure and union specifiers ($3.5.2.1), type definitions ($3.5.6), type qualifiers ($3.5.3), type specifiers ($3.5.2). 

3.1.3 Constants

Syntax

          constant:

                  floating-constant

                  integer-constant

                  enumeration-constant

                  character-constant

Constraints

   The value of a constant shall be in the range of representable values for its type. 

Semantics

   Each constant has a type, determined by its form and value, as detailed later. 

3.1.3.1 Floating constants

Syntax

          floating-constant:

                  fractional-constant exponent-part<opt> floating-suffix<opt>

                  digit-sequence exponent-part floating-suffix<opt>

          fractional-constant:

                  digit-sequence<opt> .  digit-sequence

                  digit-sequence .

          exponent-part:

                  e  sign<opt> digit-sequence

                  E  sign<opt> digit-sequence

          sign: one of

                  +  -

          digit-sequence:

                  digit

                  digit-sequence digit

          floating-suffix: one of

                  f  l  F  L

Description

   A floating constant has a value part that may be followed by an exponent part and a suffix that specifies its type.  The components of the value part may include a digit sequence representing the whole-number part, followed by a period ( . ), followed by a digit sequence representing the fraction part.  The components of the exponent part are an e or E followed by an exponent consisting of an optionally signed digit sequence.  Either the whole-number part or the fraction part shall be present; either the period or the exponent part shall be present. 

Semantics

   The value part is interpreted as a decimal rational number; the digit sequence in the exponent part is interpreted as a decimal integer.  The exponent indicates the power of 10 by which the value part is to be scaled.  If the scaled value is in the range of representable values (for its type) but cannot be represented exactly, the result is either the nearest higher or nearest lower value, chosen in an implementation-defined manner. 

   An unsuffixed floating constant has type double .  If suffixed by the letter f or F , it has type float .  If suffixed by the letter l or L , it has type long double . 

3.1.3.2 Integer constants

Syntax

          integer-constant:

                  decimal-constant integer-suffix<opt>

                  octal-constant integer-suffix<opt>

                  hexadecimal-constant integer-suffix<opt>

          decimal-constant:

                  nonzero-digit

                  decimal-constant digit

          octal-constant:

                  0

                  octal-constant octal-digit

          hexadecimal-constant:

                  0x  hexadecimal-digit

                  0X  hexadecimal-digit

                  hexadecimal-constant hexadecimal-digit

          nonzero-digit: one of

                  1  2  3  4  5  6  7  8  9

          octal-digit: one of

                  0  1  2  3  4  5  6  7

          hexadecimal-digit: one of

                  0  1  2  3  4  5  6  7  8  9

                  a  b  c  d  e  f

                  A  B  C  D  E  F

          integer-suffix:

                  unsigned-suffix long-suffix<opt>

                  long-suffix unsigned-suffix<opt>

          unsigned-suffix: one of

                  u  U

          long-suffix: one of

                  l  L

Description

   An integer constant begins with a digit, but has no period or exponent part.  It may have a prefix that specifies its base and a suffix that specifies its type. 

   A decimal constant begins with a nonzero digit and consists of a sequence of decimal digits.  An octal constant consists of the prefix 0 optionally followed by a sequence of the digits 0 through 7 only.  A hexadecimal constant consists of the prefix 0x or 0X followed by a sequence of the decimal digits and the letters a (or A ) through f (or F ) with values 10 through 15 respectively. 

Semantics

   The value of a decimal constant is computed base 10; that of an octal constant, base 8; that of a hexadecimal constant, base 16.  The lexically first digit is the most significant. 

   The type of an integer constant is the first of the corresponding list in which its value can be represented.  Unsuffixed decimal: int , long int , unsigned long int ; unsuffixed octal or hexadecimal: int , unsigned int , long int , unsigned long int ; suffixed by the letter u or U : unsigned int , unsigned long int ; suffixed by the letter l or L : long int , unsigned long int ; suffixed by both the letters u or U and l or L : unsigned long int . 

3.1.3.3 Enumeration constants

Syntax

          enumeration-constant:

                  identifier

Semantics

   An identifier declared as an enumeration constant has type int . 

Forward references: enumeration specifiers ($3.5.2.2). 

3.1.3.4 Character constants

Syntax

          character-constant:

                  ' c-char-sequence'

                  L' c-char-sequence'

          c-char-sequence:

                  c-char

                  c-char-sequence c-char

          c-char:

                  any member of the source character set except

                           the single-quote ', backslash \, or new-line character

                   escape-sequence

          escape-sequence:

                  simple-escape-sequence

                  octal-escape-sequence

                  hexadecimal-escape-sequence

          simple-escape-sequence: one of

                  \'  \"  \?  \\

                  \a  \b  \f  \n  \r  \t  \v

          octal-escape-sequence:

                  \  octal-digit

                  \  octal-digit octal-digit

                  \  octal-digit octal-digit octal-digit

          hexadecimal-escape-sequence:

                  \x  hexadecimal-digit

                  hexadecimal-escape-sequence hexadecimal-digit

Description

   An integer character constant is a sequence of one or more multibyte characters enclosed in single-quotes, as in 'x' or 'ab'.  A wide character constant is the same, except prefixed by the letter L. With a few exceptions detailed later, the elements of the sequence are any members of the source character set; they are mapped in an implementation-defined manner to members of the execution character set. 

   The single-quote ', the double-quote  , the question-mark ? , the backslash \ , and arbitrary integral values, are representable according to the following table of escape sequences:

         single-quote '    \'

         double-quote "    \"

         question-mark ?   \?

         backslash \       \\

         octal integer     \ octal digits

         hexadecimal integer        \x hexadecimal digits

   The double-quote  and question-mark ? are representable either by themselves or by the escape sequences \ and \? respectively, but the single-quote ' and the backslash \ shall be represented, respectively, by the escape sequences \' and \\ . 

   The octal digits that follow the backslash in an octal escape sequence are taken to be part of the construction of a single character for an integer character constant or of a single wide character for a wide character constant.  The numerical value of the octal integer so formed specifies the value of the desired character. 

   The hexadecimal digits that follow the backslash and the letter x in a hexadecimal escape sequence are taken to be part of the construction of a single character for an integer character constant or of a single wide character for a wide character constant.  The numerical value of the hexadecimal integer so formed specifies the value of the desired character. 

   Each octal or hexadecimal escape sequence is the longest sequence of characters that can constitute the escape sequence. 

   In addition, certain nongraphic characters are representable by escape sequences consisting of the backslash \ followed by a lower-case letter: \a , \b , \f , \n , \r , \t , and \v ./17/    If any other escape sequence is encountered, the behavior is undefined./18/

Constraints

   The value of an octal or hexadecimal escape sequence shall be in the range of representable values for the unsigned type corresponding to its type. 

Semantics

   An integer character constant has type int .  The value of an integer character constant containing a single character that maps into a member of the basic execution character set is the numerical value of the representation of the mapped character interpreted as an integer.  The value of an integer character constant containing more than one character, or containing a character or escape sequence not represented in the basic execution character set, is implementation-defined.  In particular, in an implementation in which type char has the same range of values as signed char , the high-order bit position of a single-character integer character constant is treated as a sign bit. 

   A wide character constant has type wchar_t , an integral type defined in the <stddef.h> header.  The value of a wide character constant containing a single multibyte character that maps into a member of the extended execution character set is the wide character (code) corresponding to that multibyte character, as defined by the mbtowc function, with an implementation-defined current locale.  The value of a wide character constant containing more than one multibyte character, or containing a multibyte character or escape sequence not represented in the extended execution character set, is implementation-defined. 

Examples

   The construction '\0' is commonly used to represent the null character. 

   Consider implementations that use two's-complement representation for integers and eight bits for objects that have type char .  In an implementation in which type char has the same range of values as signed char , the integer character constant '\xFF' has the value if type char has the same range of values as unsigned char , the character constant '\xFF' has the value

   Even if eight bits are used for objects that have type char , the construction '\x123' specifies an integer character constant containing only one character.  (The value of this single-character integer character constant is implementation-defined and violates the above constraint.) To specify an integer character constant containing the two characters whose values are 0x12 and '3', the construction '\0223' may be used, since a hexadecimal escape sequence is terminated only by a non-hexadecimal character.  (The value of this two-character integer character constant is implementation-defined also.)

   Even if 12 or more bits are used for objects that have type wchar_t , the construction L'\1234' specifies the implementation-defined value that results from the combination of the values 0123 and '4'. 

Forward references: characters and integers ($3.2.1.1) common definitions <stddef.h> ($4.1.5), the mbtowc function ($4.10.7.2). 

3.1.4 String literals

Syntax

          string-literal:

                  " s-char-sequence<opt>"

                  L" s-char-sequence<opt>"

          s-char-sequence:

                  s-char

                  s-char-sequence s-char

          s-char:

                  any member of the source character set except

                           the double-quote ", backslash \, or new-line character

                   escape-sequence

Description

   A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in xyz .  A wide string literal is the same, except prefixed by the letter L . 

   The same considerations apply to each element of the sequence in a character string literal or a wide string literal as if it were in an integer character constant or a wide character constant, except that the single-quote ' is representable either by itself or by the escape sequence \', but the double-quote  shall be represented by the escape sequence \ . 

Semantics

   A character string literal has static storage duration and type ``array of char ,'' and is initialized with the given characters.  A wide string literal has static storage duration and type ``array of wchar_t ,'' and is initialized with the wide characters corresponding to the given multibyte characters.  Character string literals that are adjacent tokens are concatenated into a single character string literal.  A null character is then appended./19/    Likewise, adjacent wide string literal tokens are concatenated into a single wide string literal to which a code with value zero is then appended.  If a character string literal token is adjacent to a wide string literal token, the behavior is undefined. 

   Identical string literals of either form need not be distinct.  If the program attempts to modify a string literal of either form, the behavior is undefined. 

Example

   This pair of adjacent character string literals

         "\x12" "3"

produces a single character string literal containing the two characters whose values are \x12 and '3', because escape sequences are converted into single members of the execution character set just prior to adjacent string literal concatenation. 

Forward references: common definitions <stddef.h> ($4.1.5). 

3.1.5 Operators

Syntax

          operator: one of

                  [  ]  (  )  .  ->

                  ++  --  &  *  +  -  ~  !  sizeof

                  /  %  <<  >>  <  >  <=  >=  =^=  !=  ^  |  &&  ||

                  ?  :

                  =  *=  /=  %=  +=  -=  <<=  >>=  &=  ^=  |=

                  ,  #  ##

Constraints

   The operators [ ] , ( ) , and ? : shall occur in pairs, possibly separated by expressions.  The operators # and ## shall occur in macro-defining preprocessing directives only. 

Semantics

   An operator specifies an operation to be performed (an evaluation ) that yields a value, or yields a designator, or produces a side effect, or a combination thereof.  An operand is an entity on which an operator acts. 

Forward references: expressions ($3.3), macro replacement ($3.8.3). 

3.1.6 Punctuators

Syntax

          punctuator: one of

                  [  ]  (  )  {  }  *  ,  :  =  ;  ...  #

Constraints

   The punctuators [ ] , ( ) , and { } shall occur in pairs, possibly separated by expressions, declarations, or statements.  The punctuator # shall occur in preprocessing directives only. 

Semantics

   A punctuator is a symbol that has independent syntactic and semantic significance but does not specify an operation to be performed that yields a value.  Depending on context, the same symbol may also represent an operator or part of an operator. 

Forward references: expressions ($3.3), declarations ($3.5), preprocessing directives ($3.8), statements ($3.6). 

3.1.7 Header names

Syntax

          header-name:

                  < h-char-sequence>

                  " q-char-sequence"

          h-char-sequence:

                  h-char

                  h-char-sequence h-char

          h-char:

                  any member of the source character set except

                           the new-line character and >

          q-char-sequence:

                  q-char

                  q-char-sequence q-char

          q-char:

                  any member of the source character set except

                           the new-line character and "

Constraints

   Header name preprocessing tokens shall only appear within a #include preprocessing directive. 

Semantics

   The sequences in both forms of header names are mapped in an implementation-defined manner to headers or external source file names as specified in $3.8.2. 

   If the characters ', \ ,  , or /* occur in the sequence between the < and > delimiters, the behavior is undefined.  Similarly, if the characters ', \ , or /* occur in the sequence between the  delimiters, the behavior is undefined./20/

Example

   The following sequence of characters:

         0x3<1/a.h>1e2

         #include <1/a.h>

         #define const.member@$

forms the following sequence of preprocessing tokens (with each individual preprocessing token delimited by a { on the left and a } on the right). 

         {0x3}{<}{1}{/}{a}{.}{h}{>}{1e2}

         {#}{include} {<1/a.h>}

         {#}{define} {const}{.}{member}{@}{$}

Forward references: source file inclusion ($3.8.2). 

3.1.8 Preprocessing numbers

Syntax

          pp-number:

                  digit

                  .  digit

                  pp-number  digit

                  pp-number  nondigit

                  pp-number e  sign

                  pp-number E  sign

                  pp-number .

Description

   A preprocessing number begins with a digit optionally preceded by a period ( . ) and may be followed by letters, underscores, digits, periods, and e+ , e- , E+ , or E- character sequences. 

   Preprocessing number tokens lexically include all floating and integer constant tokens. 

Semantics

   A preprocessing number does not have type or a value; it acquires both after a successful conversion (as part of translation phase 7) to a floating constant token or an integer constant token. 

3.1.9 Comments

   Except within a character constant, a string literal, or a comment, the characters /* introduce a comment.  The contents of a comment are examined only to identify multibyte characters and to find the characters */ that terminate it./21/

3.2 CONVERSIONS

   Several operators convert operand values from one type to another automatically.  This section 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 $3.2.1.5 summarizes the conversions performed by most ordinary operators; it is supplemented as required by the discussion of each operator in $3.3. 

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

Forward references: cast operators ($3.3.4). 

3.2.1 Arithmetic operands

3.2.1.1 Characters and integers

   A char , a short int , or an int bit-field, or their signed or unsigned varieties, or an object that has enumeration type, may be used in an expression wherever an int or unsigned int may be used.  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 integral promotions  .

   The integral promotions preserve value including sign.  As discussed earlier, whether a ``plain'' char is treated as signed is implementation-defined. 

Forward references: enumeration specifiers ($3.5.2.2), structure and union specifiers ($3.5.2.1). 

3.2.1.2 Signed and unsigned integers

   When an unsigned integer is converted to another integral type, if the value can be represented by the new type, its value is unchanged. 

   When a signed integer is converted to an unsigned integer with equal or greater size, if the value of the signed integer is nonnegative, its value is unchanged.  Otherwise: if the unsigned integer has greater size, the signed integer is first promoted to the signed integer corresponding to the unsigned integer; the value is converted to unsigned by adding to it one greater than the largest number that can be represented in the unsigned integer type./22/   

   When an integer is demoted to an unsigned integer with smaller size, the result is the nonnegative remainder on division by the number one greater than the largest unsigned number that can be represented in the type with smaller size.  When an integer is demoted to a signed integer with smaller size, or an unsigned integer is converted to its corresponding signed integer, if the value cannot be represented the result is implementation-defined. 

3.2.1.3 Floating and integral

   When a value of floating type is converted to integral type, the fractional part is discarded.  If the value of the integral part cannot be represented by the integral type, the behavior is undefined./23/

   When a value of integral type is converted to floating type, 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 value, chosen in an implementation-defined manner. 

3.2.1.4 Floating types

   When a float is promoted to double or long double , or a double is promoted to long double , its value is unchanged. 

   When a double is demoted to float or a long double to double or float , if the value being converted is outside the range of values that can be represented, the behavior is undefined.  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 value, chosen in an implementation-defined manner. 

3.2.1.5 Usual arithmetic conversions

   Many binary operators that expect operands of arithmetic type cause conversions and yield result types in a similar way.  The purpose is to yield a common type, which is also the type of the result.  This pattern is called the usual arithmetic conversions  :First, if either operand has type long double , the other operand is converted to long double .  Otherwise, if either operand has type double , the other operand is converted to double .  Otherwise, if either operand has type float , the other operand is converted to float .  Otherwise, the integral promotions are performed on both operands.  Then the following rules are applied: If either operand has type unsigned long int , the other operand is converted to unsigned long int .  Otherwise, if one operand has type long int and the other has type unsigned int , if a long int can represent all values of an unsigned int , the operand of type unsigned int is converted to long int ; if a long int cannot represent all the values of an unsigned int , both operands are converted to unsigned long int .  Otherwise, if either operand has type long int , the other operand is converted to long int .  Otherwise, if either operand has type unsigned int , the other operand is converted to unsigned int .  Otherwise, both operands have type int . 

   The values of operands and of the results of expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby. 

3.2.2 Other operands

3.2.2.1 Lvalues and function designators

   An lvalue is an expression (with an object type or an incomplete type other than void ) that designates an object./24/    When an object is said to have a particular type, the type is specified by the lvalue used to designate the object.  A modifiable lvalue is an lvalue that does not have array type, does not have an incomplete type, does not have a const-qualified type, and if it is a structure or union, does not have any member (including, recursively, any member of all contained structures or unions) with a const-qualified type. 

   Except when it is the operand of the sizeof operator, the unary & operator, the ++ operator, the -- operator, or the left operand of the .  operator or an assignment operator, an lvalue that does not have array type is converted to the value stored in the designated object (and is no longer an lvalue).  If the lvalue has qualified type, the value has the unqualified version of the type of the lvalue; otherwise the value has the type of the lvalue.  If the lvalue has an incomplete type and does not have array type, the behavior is undefined. 

   Except when it is the operand of the sizeof operator or the unary & operator, or is a character string literal used to initialize an array of character type, or is a wide string literal used to initialize an array with element type compatible with wchar_t , an lvalue that has type ``array of type '' is converted to an expression that has type ``pointer to type '' that points to the initial member of the array object and is not an lvalue. 

   A function designator is an expression that has function type.  Except when it is the operand of the sizeof operator/25/ or the unary & operator, a function designator with type ``function returning type '' is converted to an expression that has type ``pointer to function returning type .''

Forward references: address and indirection operators ($3.3.3.2), assignment operators ($3.3.16), common definitions <stddef.h> ($4.1.5), initialization ($3.5.7), postfix increment and decrement operators ($3.3.2.4), prefix increment and decrement operators ($3.3.3.1), the sizeof operator ($3.3.3.4), structure and union members ($3.3.2.3). 

3.2.2.2 void

   The (nonexistent) value of a void expression (an expression that has type void ) shall not be used in any way, and implicit or explicit conversions (except to void ) shall not be applied to such an expression.  If an expression of any other type occurs in a context where a void expression is required, its value or designator is discarded.  (A void expression is evaluated for its side effects.)

3.2.2.3 Pointers

   A pointer to void may be converted to or from a pointer to any incomplete or object type.  A pointer to any incomplete or object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer. 

   A pointer to a  non- q -qualified type may be converted to a pointer to the q -qualified version of the type; the values stored in the original and converted pointers shall compare equal. 

   An integral constant expression with the value 0, or such an expression cast to type void * , is called a null pointer constant  .If a null pointer constant is assigned to or compared for equality to a pointer, the constant is converted to a pointer of that type.  Such a pointer, called a null pointer  ,is guaranteed to compare unequal to a pointer to any object or function. 

   Two null pointers, converted through possibly different sequences of casts to pointer types, shall compare equal. 

Forward references: cast operators ($3.3.4), equality operators ($3.3.9), simple assignment ($3.3.16.1). 

3.3 EXPRESSIONS

   An expression is a sequence of operators and operands that specifies computation of a value, or that designates an object or a function, or that generates side effects, or that performs a combination thereof. 

   Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression.  Furthermore, the prior value shall be accessed only to determine the value to be stored./26/

   Except as indicated by the syntax/27/ or otherwise specified later (for the function-call operator () , && , || , ?: , and comma operators), the order of evaluation of subexpressions and the order in which side effects take place are both unspecified. 

   Some operators (the unary operator ~ , and the binary operators << , >> , & , ^ , and | , collectively described as bitwise operators  )shall have operands that have integral type.  These operators return values that depend on the internal representations of integers, and thus have implementation-defined aspects for signed types. 

   If an exception occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not representable), the behavior is undefined. 

   An object shall have its stored value accessed only by an lvalue that has one of the following types:/28/

 * the declared type of the object,

 * a qualified version of the declared type of the object,

 * a type that is the signed or unsigned type corresponding to the declared type of the object,

 * a type that is the signed or unsigned type corresponding to a qualified version of the declared type of the object,

 * an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union), or

 * a character type. 

3.3.1 Primary expressions

Syntax

          primary-expression:

                  identifier

                  constant

                  string-literal

                  (  expression )

Semantics

   An identifier is a primary expression, provided it has been declared as designating an object (in which case it is an lvalue) or a function (in which case it is a function designator). 

   A constant is a primary expression.  Its type depends on its form, as detailed in $3.1.3. 

   A string literal is a primary expression.  It is an lvalue with type as detailed in $3.1.4. 

   A parenthesized expression is a primary expression.  Its type and value are identical to those of the unparenthesized expression.  It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression. 

Forward references: declarations ($3.5). 

3.3.2 Postfix operators

Syntax

          postfix-expression:

                  primary-expression

                  postfix-expression [  expression ]

                  postfix-expression (  argument-expression-list<opt> )

                  postfix-expression .   identifier

                  postfix-expression ->  identifier

                  postfix-expression ++

                  postfix-expression --

          argument-expression-list:

                  assignment-expression

                  argument-expression-list ,  assignment-expression

3.3.2.1 Array subscripting

Constraints

   One of the expressions shall have type ``pointer to object type ,'' the other expression shall have integral type, and the result has type `` type .''

Semantics

   A postfix expression followed by an expression in square brackets [] is a subscripted designation of a member of an array object.  The definition of the subscript operator [] is that E1[E2] is identical to (*(E1+(E2))) .  Because of the conversion rules that apply to the binary + operator, if E1 is an array object (equivalently, a pointer to the initial member of an array object) and E2 is an integer, E1[E2] designates the E2 -th member of E1 (counting from zero). 

   Successive subscript operators designate a member of a multi-dimensional array object.  If E is an n -dimensional array ( n >=2) with dimensions i x j "x ... x" k , then E (used as other than an lvalue) is converted to a pointer to an ( n -1)-dimensional array with dimensions j "x ... x" k . If the unary * operator is applied to this pointer explicitly, or implicitly as a result of subscripting, the result is the pointed-to ( n -1)-dimensional array, which itself is converted into a pointer if used as other than an lvalue.  It follows from this that arrays are stored in row-major order (last subscript varies fastest). 

Example

   Consider the array object defined by the declaration

         int x[3][5];

Here x is a 3x5 array of int s; more precisely, x is an array of three member objects, each of which is an array of five int s.  In the expression x[i] , which is equivalent to (*(x+(i))) , x is first converted to a pointer to the initial array of five int s.  Then i is adjusted according to the type of x , which conceptually entails multiplying i by the size of the object to which the pointer points, namely an array of five int objects.  The results are added and indirection is applied to yield an array of five int s.  When used in the expression x[i][j] , that in turn is converted to a pointer to the first of the int s, so x[i][j] yields an int . 

Forward references: additive operators ($3.3.6), address and indirection operators ($3.3.3.2), array declarators ($3.5.4.2). 

3.3.2.2 Function calls

Constraints

   The expression that denotes the called function/29/ shall have type pointer to function returning void or returning an object type other than array. 

   If the expression that denotes the called function has a type that includes a prototype, the number of arguments shall agree with the number of parameters.  Each argument shall have a type such that its value may be assigned to an object with the unqualified version of the type of its corresponding parameter. 

Semantics

   A postfix expression followed by parentheses () containing a possibly empty, comma-separated list of expressions is a function call.  The postfix expression denotes the called function.  The list of expressions specifies the arguments to the function. 

   If the expression that precedes the parenthesized argument list in a function call consists solely of an identifier, and if no declaration is visible for this identifier, the identifier is implicitly declared exactly as if, in the innermost block containing the function call, the declaration

         extern int  identifier();

appeared./30/

   An argument may be an expression of any object type.  In preparing for the call to a function, the arguments are evaluated, and each parameter is assigned the value of the corresponding argument./31/    The value of the function call expression is specified in $3.6.6.4. 

   If the expression that denotes the called function has a type that does not include a prototype, the integral promotions are performed on each argument and arguments that have type float are promoted to double. These are called the default argument promotions  .If the number of arguments does not agree with the number of parameters, the behavior is undefined.  If the function is defined with a type that does not include a prototype, and the types of the arguments after promotion are not compatible with those of the parameters after promotion, the behavior is undefined.  If the function is defined with a type that includes a prototype, and the types of the arguments after promotion are not compatible with the types of the parameters, or if the prototype ends with an ellipsis ( ", ..." ), the behavior is undefined. 

   If the expression that denotes the called function has a type that includes a prototype, the arguments are implicitly converted, as if by assignment, to the types of the corresponding parameters.  The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter.  The default argument promotions are performed on trailing arguments.  If the function is defined with a type that is not compatible with the type (of the expression) pointed to by the expression that denotes the called function, the behavior is undefined. 

   No other conversions are performed implicitly; in particular, the number and types of arguments are not compared with those of the parameters in a function definition that does not include a function prototype declarator. 

   The order of evaluation of the function designator, the arguments, and subexpressions within the arguments is unspecified, but there is a sequence point before the actual call. 

   Recursive function calls shall be permitted, both directly and indirectly through any chain of other functions. 

Example

   In the function call

         (*pf[f1()]) (f2(), f3() + f4())

the functions f1 , f2 , f3 , and f4 may be called in any order.  All side effects shall be completed before the function pointed to by pf[f1()] is entered. 

Forward references: function declarators (including prototypes) ($3.5.4.3), function definitions ($3.7.1), the return statement ($3.6.6.4), simple assignment ($3.3.16.1). 

3.3.2.3 Structure and union members

Constraints

   The first operand of the .  operator shall have a qualified or unqualified structure or union type, and the second operand shall name a member of that type. 

   The first operand of the -> operator shall have type ``pointer to qualified or unqualified structure'' or ``pointer to qualified or unqualified union,'' and the second operand shall name a member of the type pointed to. 

Semantics

   A postfix expression followed by a dot .  and an identifier designates a member of a structure or union object.  The value is that of the named member, and is an lvalue if the first expression is an lvalue.  If the first expression has qualified type, the result has the so-qualified version of the type of the designated member. 

   A postfix expression followed by an arrow -> and an identifier designates a member of a structure or union object.  The value is that of the named member of the object to which the first expression points, and is an lvalue./32/    If the first expression is a pointer to a qualified type, the result has the so-qualified version of the type of the designated member. 

   With one exception, if a member of a union object is accessed after a value has been stored in a different member of the object, the behavior is implementation-defined./33/    One special guarantee is made in order to simplify the use of unions: If a union contains several structures that share a common initial sequence, and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them.  Two structures share a common initial sequence if corresponding members have compatible types for a sequence of one or more initial members. 

Example

   If f is a function returning a structure or union, and x is a member of that structure or union, f().x is a valid postfix expression but is not an lvalue. 

   The following is a valid fragment:

         union {

                  struct {

                           int      alltypes;

                  } n;

                  struct {

                           int      type;

                           int      intnode;

                  } ni;

                  struct {

                           int      type;

                           double   doublenode;

                  } nf;

         } u;

         /*...*/

         u.nf.type = 1;

         u.nf.doublenode = 3.14;

         /*...*/

         if (u.n.alltypes =^= 1)

                  /*...*/ sin(u.nf.doublenode) /*...*/

Forward references: address and indirection operators ($3.3.3.2), structure and union specifiers ($3.5.2.1). 

3.3.2.4 Postfix increment and decrement operators

Constraints

   The operand of the postfix increment or decrement operator shall have qualified or unqualified scalar type and shall be a modifiable lvalue. 

Semantics

   The result of the postfix ++ operator is the value of the operand.  After the result is obtained, the value of the operand is incremented.  (That is, the value 1 of the appropriate type is added to it.) See the discussions of additive operators and compound assignment for information on constraints, types and conversions and the effects of operations on pointers.  The side effect of updating the stored value of the operand shall occur between the previous and the next sequence point. 

   The postfix -- operator is analogous to the postfix ++ operator, except that the value of the operand is decremented (that is, the value 1 of the appropriate type is subtracted from it). 

Forward references: additive operators ($3.3.6), compound assignment ($3.3.16.2). 

3.3.3 Unary operators

Syntax

          unary-expression:

                  postfix-expression

                  ++  unary-expression

                  --  unary-expression

                  unary-operator cast-expression

                  sizeof  unary-expression

                  sizeof (  type-name )

          unary-operator: one of

                  &  *  +  -  ~  !

3.3.3.1 Prefix increment and decrement operators

Constraints

   The operand of the prefix increment or decrement operator shall have qualified or unqualified scalar type and shall be a modifiable lvalue. 

Semantics

   The value of the operand of the prefix ++ operator is incremented.  The result is the new value of the operand after incrementation.  The expression ++E is equivalent to (E+=1) .  See the discussions of additive operators and compound assignment for information on constraints, types, side effects, and conversions and the effects of operations on pointers. 

   The prefix -- operator is analogous to the prefix ++ operator, except that the value of the operand is decremented. 

Forward references: additive operators ($3.3.6), compound assignment ($3.3.16.2). 

3.3.3.2 Address and indirection operators

Constraints

   The operand of the unary & operator shall be either a function designator or an lvalue that designates an object that is not a bit-field and is not declared with the register storage-class specifier. 

   The operand of the unary * operator shall have pointer type. 

Semantics

   The result of the unary & (address-of) operator is a pointer to the object or function designated by its operand.  If the operand has type `` type ,'' the result has type ``pointer to type .''

   The unary * operator denotes indirection.  If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object.  If the operand has type ``pointer to type ,'' the result has type `` type .'' If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined./34/

Forward references: storage-class specifiers ($3.5.1), structure and union specifiers ($3.5.2.1). 

3.3.3.3 Unary arithmetic operators

Constraints

   The operand of the unary + or - operator shall have arithmetic type; of the ~ operator, integral type; of the ! operator, scalar type. 

Semantics

   The result of the unary + operator is the value of its operand.  The integral promotion is performed on the operand, and the result has the promoted type. 

   The result of the unary - operator is the negative of its operand.  The integral promotion is performed on the operand, and the result has the promoted type. 

   The result of the ~ operator is the bitwise complement of its operand (that is, each bit in the result is set if and only if the corresponding bit in the converted operand is not set).  The integral promotion is performed on the operand, and the result has the promoted type.  The expression ~E is equivalent to (ULONG_MAX-E) if E is promoted to type unsigned long , to (UINT_MAX-E) if E is promoted to type unsigned int .  (The constants ULONG_MAX and UINT_MAX are defined in the header <limits.h> .)

   The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0.  The result has type int .  The expression !E is equivalent to (0=^=E) . 

Forward references: limits <float.h> and <limits.h> ($4.1.4). 

3.3.3.4 The sizeof operator

Constraints

   The sizeof operator shall not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an lvalue that designates a bit-field object. 

Semantics

   The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type.  The size is determined from the type of the operand, which is not itself evaluated.  The result is an integer constant. 

   When applied to an operand that has type char , unsigned char , or signed char , (or a qualified version thereof) the result is 1.  When applied to an operand that has array type, the result is the total number of bytes in the array./35/    When applied to an operand that has structure or union type, the result is the total number of bytes in such an object, including internal and trailing padding. 

   The value of the result is implementation-defined, and its type (an unsigned integral type) is size_t defined in the <stddef.h> header. 

Examples

   A principal use of the sizeof operator is in communication with routines such as storage allocators and I/O systems.  A storage-allocation function might accept a size (in bytes) of an object to allocate and return a pointer to void .  For example:

         extern void *alloc();

         double *dp = alloc(sizeof *dp);

The implementation of the alloc function should ensure that its return value is aligned suitably for conversion to a pointer to double . 

   Another use of the sizeof operator is to compute the number of members in an array:

         sizeof array / sizeof array[0]

Forward references: common definitions <stddef.h> ($4.1.5), declarations ($3.5), structure and union specifiers ($3.5.2.1), type names ($3.5.5). 

3.3.4 Cast operators

Syntax

          cast-expression:

                  unary-expression

                  (  type-name )  cast-expression

Constraints

   Unless the type name specifies void type, the type name shall specify qualified or unqualified scalar type and the operand shall have scalar type. 

Semantics

   Preceding an expression by a parenthesized type name converts the value of the expression to the named type.  This construction is called a cast ./36/    A cast that specifies an implicit conversion or no conversion has no effect on the type or value of an expression. 

   Conversions that involve pointers (other than as permitted by the constraints of $3.3.16.1) shall be specified by means of an explicit cast; they have implementation-defined aspects: A pointer may be converted to an integral type.  The size of integer required and the result are implementation-defined.  If the space provided is not long enough, the behavior is undefined.  An arbitrary integer may be converted to a pointer.  The result is implementation-defined./37/    A pointer to an object or incomplete type may be converted to a pointer to a different object type or a different incomplete type.  The resulting pointer might not be valid if it is improperly aligned for the type pointed to.  It is guaranteed, however, that a pointer to an object of a given alignment may be converted to a pointer to an object of the same alignment or a less strict alignment and back again; the result shall compare equal to the original pointer.  (An object that has character type has the least strict alignment.) A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original pointer.  If a converted pointer is used to call a function that has a type that is not compatible with the type of the called function, the behavior is undefined. 

Forward references: equality operators ($3.3.9), function declarators (including prototypes) ($3.5.4.3), simple assignment ($3.3.16.1), type names ($3.5.5). 

3.3.5 Multiplicative operators

Syntax

          multiplicative-expression:

                  cast-expression

                  multiplicative-expression *  cast-expression

                  multiplicative-expression /  cast-expression

                  multiplicative-expression %  cast-expression

Constraints

   Each of the operands shall have arithmetic type.  The operands of the % operator shall have integral type. 

Semantics

   The usual arithmetic conversions are performed on the operands. 

   The result of the binary * operator is the product of the operands. 

   The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder.  In both operations, if the value of the second operand is zero, the behavior is undefined. 

   When integers are divided and the division is inexact, if both operands are positive the result of the / operator is the largest integer less than the algebraic quotient and the result of the % operator is positive.  If either operand is negative, whether the result of the / operator is the largest integer less than the algebraic quotient or the smallest integer greater than the algebraic quotient is implementation-defined, as is the sign of the result of the % operator.  If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a . 

3.3.6 Additive operators

Syntax

          additive-expression:

                  multiplicative-expression

                  additive-expression +  multiplicative-expression

                  additive-expression -  multiplicative-expression

Constraints

   For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to an object type and the other shall have integral type.  (Incrementing is equivalent to adding 1.)

   For subtraction, one of the following shall hold:

 * both operands have arithmetic type;

 * both operands are pointers to qualified or unqualified versions of compatible object types; or

 * the left operand is a pointer to an object type and the right operand has integral type.  (Decrementing is equivalent to subtracting 1.)

Semantics

   If both operands have arithmetic type, the usual arithmetic conversions are performed on them. 

   The result of the binary + operator is the sum of the operands. 

   The result of the binary - operator is the difference resulting from the subtraction of the second operand from the first. 

   When an expression that has integral type is added to or subtracted from a pointer, the integral value is first multiplied by the size of the object pointed to.  The result has the type of the pointer operand.  If the pointer operand points to a member of an array object, and the array object is large enough, the result points to a member of the same array object, appropriately offset from the original member.  Thus if P points to a member of an array object, the expression P+1 points to the next member of the array object.  Unless both the pointer operand and the result point to a member of the same array object, or one past the last member of the array object, the behavior is undefined.  Unless both the pointer operand and the result point to a member of the same array object, or the pointer operand points one past the last member of an array object and the result points to a member of the same array object, the behavior is undefined if the result is used as the operand of a unary * operator. 

   When two pointers to members of the same array object are subtracted, the difference is divided by the size of a member.  The result represents the difference of the subscripts of the two array members.  The size of the result is implementation-defined, and its type (a signed integral type) is ptrdiff_t defined in the <stddef.h> header.  As with any other arithmetic overflow, if the result does not fit in the space provided, the behavior is undefined.  If two pointers that do not point to members of the same array object are subtracted, the behavior is undefined.  However, if P points either to a member of an array object or one past the last member of an array object, and Q points to the last member of the same array object, the expression (Q+1) - P has the same value as (Q-P) + 1 , even though Q+1 does not point to a member of the array object. 

Forward references: common definitions <stddef.h> ($4.1.5). 

3.3.7 Bitwise shift operators

Syntax

          shift-expression:

                  additive-expression

                  shift-expression <<  additive-expression

                  shift-expression >>  additive-expression

Constraints

   Each of the operands shall have integral type. 

Semantics

   The integral promotions are performed on each of the operands.  The type of the result is that of the promoted left operand.  If the value of the right operand is negative or is greater than or equal to the width in bits of the promoted left operand, the behavior is undefined. 

   The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros.  If E1 has an unsigned type, the value of the result is E1 multiplied by the quantity, 2 raised to the power E2 , reduced modulo ULONG_MAX+1 if E1 has type unsigned long , UINT_MAX+1 otherwise.  (The constants ULONG_MAX and UINT_MAX are defined in the header <limits.h> .)

   The result of E1 >> E2 is E1 right-shifted E2 bit positions.  If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 divided by the quantity, 2 raised to the power E2 .  If E1 has a signed type and a negative value, the resulting value is implementation-defined. 

3.3.8 Relational operators

Syntax

          relational-expression:

                  shift-expression

                  relational-expression <   shift-expression

                  relational-expression >   shift-expression

                  relational-expression <=  shift-expression

                  relational-expression >=  shift-expression

Constraints

   One of the following shall hold:

 * both operands have arithmetic type;

 * both operands are pointers to qualified or unqualified versions of compatible object types; or

 * both operands are pointers to qualified or unqualified versions of compatible incomplete types. 

Semantics

   If both of the operands have arithmetic type, the usual arithmetic conversions are performed. 

   When two pointers are compared, the result depends on the relative locations in the address space of the objects pointed to.  If the objects pointed to are members of the same aggregate object, pointers to structure members declared later compare higher than pointers to members declared earlier in the structure, and pointers to array elements with larger subscript values compare higher than pointers to elements of the same array with lower subscript values.  All pointers to members of the same union object compare equal.  If the objects pointed to are not members of the same aggregate or union object, the result is undefined, with the following exception.  If P points to the last member of an array object and Q points to a member of the same array object, the pointer expression P+1 compares higher than Q , even though P+1 does not point to a member of the array object. 

   Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false./38/    The result has type int . 

3.3.9 Equality operators

Syntax

          equality-expression:

                  relational-expression

                  equality-expression =^=  relational-expression

                  equality-expression !=  relational-expression

Constraints

   One of the following shall hold:

 * both operands have arithmetic type;

 * both operands are pointers to qualified or unqualified versions of compatible types;

 * one operand is a pointer to an object or incomplete type and the other is a qualified or unqualified version of void ; or

 * one operand is a pointer and the other is a null pointer constant. 

Semantics

   The =^= (equal to) and the != (not equal to) operators are analogous to the relational operators except for their lower precedence./39/   

   If two pointers to object or incomplete types compare equal, they point to the same object.  If two pointers to functions compare equal, they point to the same function.  If two pointers point to the same object or function, they compare equal./40/    If one of the operands is a pointer to an object or incomplete type and the other has type pointer to a qualified or unqualified version of void , the pointer to an object or incomplete type is converted to the type of the other operand. 

 

3.3.10 Bitwise AND operator

Syntax

          AND-expression:

                  equality-expression

                  AND-expression &  equality-expression

Constraints

   Each of the operands shall have integral type. 

Semantics

   The usual arithmetic conversions are performed on the operands. 

   The result of the binary & operator is the bitwise  AND of the operands (that is, each bit in the result is set if and only if each of the corresponding bits in the converted operands is set). 

3.3.11 Bitwise exclusive OR operator

Syntax

          exclusive-OR-expression:

                  AND-expression

                  exclusive-OR-expression ^  AND-expression

Constraints

   Each of the operands shall have integral type. 

Semantics

   The usual arithmetic conversions are performed on the operands. 

   The result of the ^ operator is the bitwise exclusive  OR of the operands (that is, each bit in the result is set if and only if exactly one of the corresponding bits in the converted operands is set). 

3.3.12 Bitwise inclusive OR operator

Syntax

          inclusive-OR-expression:

                  exclusive-OR-expression

                  inclusive-OR-expression |  exclusive-OR-expression

Constraints

   Each of the operands shall have integral type. 

Semantics

   The usual arithmetic conversions are performed on the operands. 

   The result of the | operator is the bitwise inclusive  OR of the operands (that is, each bit in the result is set if and only if at least one of the corresponding bits in the converted operands is set). 

3.3.13 Logical AND operator

Syntax

          logical-AND-expression:

                  inclusive-OR-expression

                  logical-AND-expression &&  inclusive-OR-expression

Constraints

   Each of the operands shall have scalar type.  

Semantics

   The && operator shall yield 1 if both of its operands compare unequal to 0, otherwise it yields 0.  The result has type int . 

   Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand.  If the first operand compares equal to 0, the second operand is not evaluated. 

3.3.14 Logical OR operator

Syntax

          logical-OR-expression:

                  logical-AND-expression

                  logical-OR-expression ||  logical-AND-expression

Constraints

   Each of the operands shall have scalar type. 

Semantics

   The || operator shall yield 1 if either of its operands compare unequal to 0, otherwise it yields 0.  The result has type int . 

   Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand.  If the first operand compares unequal to 0, the second operand is not evaluated. 

3.3.15 Conditional operator

Syntax

          conditional-expression:

                  logical-OR-expression

                  logical-OR-expression ?  expression :  conditional-expression

Constraints

   The first operand shall have scalar type. 

   One of the following shall hold for the second and third operands:

 * both operands have arithmetic type;

 * both operands have compatible structure or union types;

 * both operands have void type;

 * both operands are pointers to qualified or unqualified versions of compatible types;

 * one operand is a pointer and the other is a null pointer constant; or

 * one operand is a pointer to an object or incomplete type and the other is a pointer to a qualified or unqualified version of void . 

Semantics

   The first operand is evaluated; there is a sequence point after its evaluation.  The second operand is evaluated only if the first compares unequal to 0; the third operand is evaluated only if the first compares equal to 0; the value of the second or third operand (whichever is evaluated) is the result./41/

   If both the second and third operands have arithmetic type, the usual arithmetic conversions are performed to bring them to a common type and the result has that type.  If both the operands have structure or union type, the result has that type.  If both operands have void type, the result has void type. 

   If both the second and third operands are pointers or one is a null pointer constant and the other is a pointer, the result type is a pointer to a type qualified with all the type qualifiers of the types pointed-to by both operands.  Furthermore, if both operands are pointers to compatible types or differently qualified versions of a compatible type, the result has the composite type; if one operand is a null pointer constant, the result has the type of the other operand; otherwise, one operand is a pointer to void or a qualified version of void , in which case the other operand is converted to type pointer to void , and the result has that type. 

3.3.16 Assignment operators

Syntax

          assignment-expression:

                  conditional-expression

                  unary-expression assignment-operator assignment-expression

          assignment-operator: one of

                  =  *=  /=  %=  +=  -=  <<=  >>=  &=  ^=  |=

Constraints

   An assignment operator shall have a modifiable lvalue as its left operand. 

Semantics

   An assignment operator stores a value in the object designated by the left operand.  An assignment expression has the value of the left operand after the assignment, but is not an lvalue.  The type of an assignment expression is the type of the left operand unless the left operand has qualified type, in which case it is the unqualified version of the type of the left operand.  The side effect of updating the stored value of the left operand shall occur between the previous and the next sequence point. 

   The order of evaluation of the operands is unspecified. 

3.3.16.1 Simple assignment

Constraints

   One of the following shall hold:/42/

 * the left operand has qualified or unqualified arithmetic type and the right has arithmetic type;

 * the left operand has a qualified or unqualified version of a structure or union type compatible with the type of the right;

 * both operands are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right;

 * one operand is a pointer to an object or incomplete type and the other is a pointer to a qualified or unqualified version of void , and the type pointed to by the left has all the qualifiers of the type pointed to by the right; or

 * the left operand is a pointer and the right is a null pointer constant. 

Semantics

   In simple assignment ( = ), the value of the right operand is converted to the type of the assignment expression and replaces the value stored in the object designated by the left operand. 

   If the value being stored in an object is accessed from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two objects shall have qualified or unqualified versions of a compatible type; otherwise the behavior is undefined. 

Example

   In the program fragment

         int f(void);

         char c;

         /*...*/

         /*...*/ ((c = f()) =^= -1) /*...*/

the int value returned by the function may be truncated when stored in the char , and then converted back to int width prior to the comparison.  In an implementation in which ``plain'' char has the same range of values as unsigned char (and char is narrower than int ), the result of the conversion cannot be negative, so the operands of the comparison can never compare equal.  Therefore, for full portability the variable c should be declared as int . 

3.3.16.2 Compound assignment

Constraints

   For the operators += and -= only, either the left operand shall be a pointer to an object type and the right shall have integral type, or the left operand shall have qualified or unqualified arithmetic type and the right shall have arithmetic type. 

   For the other operators, each operand shall have arithmetic type consistent with those allowed by the corresponding binary operator. 

Semantics

   A compound assignment of the form E1 op = E2 differs from the simple assignment expression E1 = E1 op (E2) only in that the lvalue E1 is evaluated only once. 

3.3.17 Comma operator

Syntax

          expression:

                  assignment-expression

                  expression ,  assignment-expression

Semantics

   The left operand of a comma operator is evaluated as a void expression; there is a sequence point after its evaluation.  Then the right operand is evaluated; the result has its type and value./43/   

Example

   As indicated by the syntax, in contexts where a comma is a punctuator (in lists of arguments to functions and lists of initializers) the comma operator as described in this section cannot appear.  On the other hand, it can be used within a parenthesized expression or within the second expression of a conditional operator in such contexts.  In the function call

         f(a, (t=3, t+2), c)

the function has three arguments, the second of which has the value 5. 

Forward references: initialization ($3.5.7). 

3.4 CONSTANT EXPRESSIONS

Syntax

           constant-expression:

                  conditional-expression

Description

    A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be. 

Constraints

    Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within the operand of a sizeof operator./44/

   Each constant expression shall evaluate to a constant that is in the range of representable values for its type. 

Semantics

   An expression that evaluates to a constant is required in several contexts./45/    If the expression is evaluated in the translation environment, the arithmetic precision and range shall be at least as great as if the expression were being evaluated in the execution environment. 

   An integral constant expression shall have integral type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions, and floating constants that are the immediate operands of casts.  Cast operators in an integral constant expression shall only convert arithmetic types to integral types, except as part of an operand to the sizeof operator. 

   More latitude is permitted for constant expressions in initializers.  Such a constant expression shall evaluate to one of the following:

 * an arithmetic constant expression,

 * an address constant, or

 * an address constant for an object type plus or minus an integral constant expression. 

   An arithmetic constant expression shall have arithmetic type and shall only have operands that are integer constants, floating constants, enumeration constants, character constants, and sizeof expressions.  Cast operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic types, except as part of an operand to the sizeof operator. 

   An address constant is a pointer to an lvalue designating an object of static storage duration, or to a function designator; it shall be created explicitly, using the unary & operator, or implicitly, by the use of an expression of array or function type.  The array-subscript [] and member-access .  and -> operators, the address & and indirection * unary operators, and pointer casts may be used in the creation an address constant, but the value of an object shall not be accessed by use of these operators. 

   The semantic rules for the evaluation of a constant expression are the same as for non-constant expressions./46/

Forward references: initialization ($3.5.7). 

3.5 DECLARATIONS

Syntax

          declaration:

                  declaration-specifiers init-declarator-list<opt> ;

          declaration-specifiers:

                  storage-class-specifier declaration-specifiers<opt>

                  type-specifier declaration-specifiers<opt>

                  type-qualifier declaration-specifiers<opt>

          init-declarator-list:

                  init-declarator

                  init-declarator-list ,  init-declarator

          init-declarator:

                  declarator

                  declarator =  initializer

Constraints

   A declaration shall declare at least a declarator, a tag, or the members of an enumeration. 

   If an identifier has no linkage, there shall be no more than one declaration of the identifier (in a declarator or type specifier) with the same scope and in the same name space, except for tags as specified in $3.5.2.3. 

   All declarations in the same scope that refer to the same object or function shall specify compatible types. 

Semantics

   A declaration specifies the interpretation and attributes of a set of identifiers.  A declaration that also causes storage to be reserved for an object or function named by an identifier is a definition ./47/   

   The declaration specifiers consist of a sequence of specifiers that indicate the linkage, storage duration, and part of the type of the entities that the declarators denote.  The init-declarator-list is a comma-separated sequence of declarators, each of which may have additional type information, or an initializer, or both.  The declarators  contain the identifiers (if any) being declared. 

   If an identifier for an object is declared with no linkage, the type for the object shall be complete by the end of its declarator, or by the end of its init-declarator if it has an initializer. 

 

Forward references: declarators ($3.5.4), enumeration specifiers ($3.5.2.2), initialization ($3.5.7), tags ($3.5.2.3). 

3.5.1 Storage-class specifiers

Syntax

          storage-class-specifier:

                  typedef

                  extern

                  static

                  auto

                  register

Constraints

   At most one storage-class specifier may be given in the declaration specifiers in a declaration./48/

 

Semantics

   The typedef specifier is called a ``storage-class specifier'' for syntactic convenience only; it is discussed in $3.5.6.  The meanings of the various linkages and storage durations were discussed in $3.1.2.2 and $3.1.2.4. 

   A declaration of an identifier for an object with storage-class specifier register suggests that access to the object be as fast as possible.  The extent to which such suggestions are effective is implementation-defined./49/   

   The declaration of an identifier for a function that has block scope shall have no explicit storage-class specifier other than extern . 

Forward references: type definitions ($3.5.6). 

3.5.2 Type specifiers

Syntax

          type-specifier:

                  void

                  char

                  short

                  int

                  long

                  float

                  double

                  signed

                  unsigned

                   struct-or-union-specifier

                  enum-specifier

                  typedef-name

Constraints

Each list of type specifiers shall be one of the following sets; the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers. 

 * void

 * char

 * signed char

 * unsigned char

 * short , signed short , short int , or signed short int

 * unsigned short , or unsigned short int

 * int , signed , signed int , or no type specifiers

 * unsigned , or unsigned int

 * long , signed long , long int , or signed long int

 * unsigned long , or unsigned long int

 * float

 * double

 * long double

 * struct-or-union specifier

 * enum-specifier

 * typedef-name

Semantics

   Specifiers for structures, unions, and enumerations are discussed in $3.5.2.1 through $3.5.2.3.  Declarations of typedef names are discussed in $3.5.6.  The characteristics of the other types are discussed in $3.1.2.5. 

   Each of the above comma-separated lists designates the same type, except that for bit-field declarations, signed int (or signed ) may differ from int (or no type specifiers). 

Forward references: enumeration specifiers ($3.5.2.2), structure and union specifiers ($3.5.2.1), tags ($3.5.2.3), type definitions ($3.5.6). 

3.5.2.1 Structure and union specifiers

Syntax

          struct-or-union-specifier:

                  struct-or-union identifier<opt> {  struct-declaration-list }

                  struct-or-union identifier

          struct-or-union:

                  struct

                  union

          struct-declaration-list:

                  struct-declaration

                  struct-declaration-list struct-declaration

          struct-declaration:

                  specifier-qualifier-list struct-declarator-list ;

          specifier-qualifier-list:

                  type-specifier specifier-qualifier-list<opt>

                  type-qualifier specifier-qualifier-list<opt>

          struct-declarator-list:

                  struct-declarator

                  struct-declarator-list ,  struct-declarator

          struct-declarator:

                  declarator

                  declarator<opt> :  constant-expression

Constraints

   A structure or union shall not contain a member with incomplete or function type. Hence it shall not contain an instance of itself (but may contain a pointer to an instance of itself). 

   The expression that specifies the width of a bit-field shall be an integral constant expression that has nonnegative value that shall not exceed the number of bits in an ordinary object of compatible type.  If the value is zero, the declaration shall have no declarator. 

Semantics

   As discussed in $3.1.2.5, a structure is a type consisting of a sequence of named members, whose storage is allocated in an ordered sequence, and a union is a type consisting of a sequence of named members, whose storage overlap. 

   Structure and union specifiers have the same form. 

   The presence of a struct-declaration-list in a struct-or-union-specifier declares a new type, within a translation unit.  The struct-declaration-list is a sequence of declarations for the members of the structure or union.  The type is incomplete until after the } that terminates the list. 

   A member of a structure or union may have any object type.  In addition, a member may be declared to consist of a specified number of bits (including a sign bit, if any).  Such a member is called a bit-field ;/50/ its width is preceded by a colon. 

   A bit-field may have type int , unsigned int , or signed int .  Whether the high-order bit position of a ``plain'' int bit-field is treated as a sign bit is implementation-defined.  A bit-field is interpreted as an integral type consisting of the specified number of bits. 

   An implementation may allocate any addressable storage unit large enough to hold a bit-field.  If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit.  If insufficient space remains, whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is implementation-defined.  The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined.  The alignment of the addressable storage unit is unspecified. 

   A bit-field declaration with no declarator, but only a colon and a width, indicates an unnamed bit-field./51/    As a special case of this, a bit-field with a width of 0 indicates that no further bit-field is to be packed into the unit in which the previous bit-field, if any, was placed. 

   Each non-bit-field member of a structure or union object is aligned in an implementation-defined manner appropriate to its type. 

   Within a structure object, the non-bit-field members and the units in which bit-fields reside have addresses that increase in the order in which they are declared.  A pointer to a structure object, suitably cast, points to its initial member (or if that member is a bit-field, then to the unit in which it resides), and vice versa.  There may therefore be unnamed holes within a structure object, but not at its beginning, as necessary to achieve the appropriate alignment. 

   The size of a union is sufficient to contain the largest of its members.  The value of at most one of the members can be stored in a union object at any time.  A pointer to a union object, suitably cast, points to each of its members (or if a member is a bit-field, then to the unit in which it resides), and vice versa. 

   There may also be unnamed padding at the end of a structure or union, as necessary to achieve the appropriate alignment were the structure or union to be a member of an array. 

3.5.2.2 Enumeration specifiers

Syntax

          enum-specifier:

                  enum  identifier<opt> {  enumerator-list }

                  enum  identifier

          enumerator-list:

                  enumerator

                  enumerator-list ,  enumerator

          enumerator:

                  enumeration-constant

                  enumeration-constant =  constant-expression

Constraints

   The expression that defines the value of an enumeration constant shall be an integral constant expression that has a value representable as an int . 

Semantics

   The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted./52/    An enumerator with = defines its enumeration constant as the value of the constant expression.  If the first enumerator has no = , the value of its enumeration constant is 0.  Each subsequent enumerator with no = defines its enumeration constant as the value of the constant expression obtained by adding 1 to the value of the previous enumeration constant.  (A combination of both forms of enumerators may produce enumeration constants with values that duplicate other values in the same enumeration.) The enumerators of an enumeration are also known as its members. 

   Each enumerated type shall be compatible with an integer type; the choice of type is implementation-defined. 

Example

         enum hue { chartreuse, burgundy, claret=20, winedark };

         /*...*/

         enum hue col, *cp;

         /*...*/

         col = claret;

         cp = &col;

         /*...*/

         /*...*/ (*cp != burgundy) /*...*/

makes hue the tag of an enumeration, and then declares col as an object that has that type and cp as a pointer to an object that has that type.  The enumerated values are in the set {0, 1, 20, 21}. 

3.5.2.3 Tags

   A type specifier of the form

          struct-or-union identifier {  struct-declaration-list }

         enum  identifier {  enumerator-list }

declares the identifier to be the tag of the structure, union, or enumeration specified by the list.  The list defines the structure content  ,union content  ,or enumeration content  .If this declaration of the tag is visible, a subsequent declaration that uses the tag and that omits the bracketed list specifies the declared structure, union, or enumerated type.  Subsequent declarations in the same scope shall omit the bracketed list. 

   If a type specifier of the form

          struct-or-union identifier

occurs prior to the declaration that defines the content, the structure or union is an incomplete type./53/    It declares a tag that specifies a type that may be used only when the size of an object of the specified type is not needed./54/    If the type is to be completed, another declaration of the tag in the same scope (but not in an enclosed block, which declares a new type known only within that block) shall define the content.  A declaration of the form

          struct-or-union identifier ;

specifies a structure or union type and declares a tag, both visible only within the scope in which the declaration occurs.  It specifies a new type distinct from any type with the same tag in an enclosing scope (if any). 

   A type specifier of the form

          struct-or-union {  struct-declaration-list }

         enum {  enumerator-list }

specifies a new structure, union, or enumerated type, within the translation unit, that can only be referred to by the declaration of which it is a part./55/

Examples

   This mechanism allows declaration of a self-referential structure. 

         struct tnode {

                  int count;

                  struct tnode *left, *right;

         };

specifies a structure that contains an integer and two pointers to objects of the same type.  Once this declaration has been given, the declaration

         struct tnode s, *sp;

declares s to be an object of the given type and sp to be a pointer to an object of the given type.  With these declarations, the expression sp->left refers to the left struct tnode pointer of the object to which sp points; the expression s.right->count designates the count member of the right struct tnode pointed to from s . 

   The following alternative formulation uses the typedef mechanism:

         typedef struct tnode TNODE;

         struct tnode {

                  int count;

                  TNODE *left, *right;

         };

         TNODE s, *sp;

   To illustrate the use of prior declaration of a tag to specify a pair of mutually-referential structures, the declarations

         struct s1 { struct s2 *s2p; /*...*/ }; /* D1 */

         struct s2 { struct s1 *s1p; /*...*/ }; /* D2 */

specify a pair of structures that contain pointers to each other.  Note, however, that if s2 were already declared as a tag in an enclosing scope, the declaration D1 would refer to it , not to the tag s2 declared in D2 .  To eliminate this context sensitivity, the otherwise vacuous declaration

         struct s2;

may be inserted ahead of D1 .  This declares a new tag s2 in the inner scope; the declaration D2 then completes the specification of the new type. 

Forward references: type definitions ($3.5.6). 

3.5.3 Type qualifiers

Syntax

          type-qualifier:

                  const

                  volatile

Constraints

   The same type qualifier shall not appear more than once in the same specifier list or qualifier list, either directly or via one or more typedef s. 

Semantics

   The properties associated with qualified types are meaningful only for expressions that are lvalues./56/

   If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined.  If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with non-volatile-qualified type, the behavior is undefined./57/

   An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects.  Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in $2.1.2.3.  Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously./58/    What constitutes an access to an object that has volatile-qualified type is implementation-defined. 

   If the specification of an array type includes any type qualifiers, the element type is so-qualified, not the array type.  If the specification of a function type includes any type qualifiers, the behavior is undefined./59/

   For two qualified types to be compatible, both shall have the identically qualified version of a compatible type; the order of type qualifiers within a list of specifiers or qualifiers does not affect the specified type. 

Examples

   An object declared

         extern const volatile int real_time_clock;

may be modifiable by hardware, but cannot be assigned to, incremented, or decremented. 

   The following declarations and expressions illustrate the behavior when type qualifiers modify an aggregate type:

         const struct s { int mem; } cs = { 1 };

         struct s ncs;  /*  the object ncs  is modifiable */

         typedef int A[2][3];

         const A a = {{4, 5, 6}, {7, 8, 9}}; /*  array of array of const  int  */

         int *pi;

         const int *pci;

         ncs = cs;      /*  valid */

         cs = ncs;      /*  violates modifiable lvalue constraint for = */

         pi = &ncs.mem; /*  valid */

         pi = &cs.mem;  /*  violates type constraints for = */

         pci = &cs.mem; /*  valid */

         pi = a[0];     /*  invalid: a[0]  has type ``const int * '' */

3.5.4 Declarators

Syntax

          declarator:

                  pointer<opt> direct-declarator

          direct-declarator:

                  identifier

                  (  declarator )

                  direct-declarator [  constant-expression<opt> ]

                  direct-declarator (  parameter-type-list )

                  direct-declarator (  identifier-list<opt> )

          pointer:

                  *  type-qualifier-list<opt>

                  *  type-qualifier-list<opt> pointer

          type-qualifier-list:

                  type-qualifier

                  type-qualifier-list type-qualifier

          parameter-type-list:

                  parameter-list

                  parameter-list , ...

          parameter-list:

                  parameter-declaration

                  parameter-list ,  parameter-declaration

          parameter-declaration:

                  declaration-specifiers declarator

                  declaration-specifiers abstract-declarator<opt>

          identifier-list:

                  identifier

                  identifier-list ,  identifier

Semantics

   Each declarator declares one identifier, and asserts that when an operand of the same form as the declarator appears in an expression, it designates a function or object with the scope, storage duration, and type indicated by the declaration specifiers. 

   In the following subsections, consider a declaration

         T D1

where T contains the declaration specifiers that specify a type T (such as int ) and D1 is a declarator that contains an identifier ident . The type specified for the identifier ident in the various forms of declarator is described inductively using this notation. 

   If, in the declaration `` T D1 ,'' D1 has the form

          identifier

then the type specified for ident is T .

   If, in the declaration `` T D1 ,'' D1 has the form

         ( D )

then ident has the type specified by the declaration `` T D .'' Thus, a declarator in parentheses is identical to the unparenthesized declarator, but the binding of complex declarators may be altered by parentheses. 

"Implementation limits"

   The implementation shall allow the specification of types that have at least 12 pointer, array, and function declarators (in any valid combinations) modifying an arithmetic, a structure, a union, or an incomplete type, either directly or via one or more typedef s. 

Forward references: type definitions ($3.5.6). 

3.5.4.1 Pointer declarators

Semantics

   If, in the declaration `` T D1 ,'' D1 has the form

         *  type-qualifier-list<opt> D

and the type specified for ident in the declaration `` T D '' is `` "derived-declarator-type-list T" ,'' then the type specified for ident is `` "derived-declarator-type-list type-qualifier-list" pointer to T .'' For each type qualifier in the list, ident is a so-qualified pointer. 

   For two pointer types to be compatible, both shall be identically qualified and both shall be pointers to compatible types. 

Examples

   The following pair of declarations demonstrates the difference between a ``variable pointer to a constant value'' and a ``constant pointer to a variable value.''

         const int *ptr_to_constant;

         int *const constant_ptr;

The contents of the const int pointed to by ptr_to_constant shall not be modified, but ptr_to_constant itself may be changed to point to another const int .  Similarly, the contents of the int pointed to by constant_ptr may be modified, but constant_ptr itself shall always point to the same location. 

   The declaration of the constant pointer constant_ptr may be clarified by including a definition for the type ``pointer to int .''

         typedef int *int_ptr;

         const int_ptr constant_ptr;

declares constant_ptr as an object that has type ``const-qualified pointer to int .''

3.5.4.2 Array declarators

Constraints

   The expression that specifies the size of an array shall be an integral constant expression that has a value greater than zero. 

Semantics

   If, in the declaration `` T D1 ,'' D1 has the form

         D[ constant-expression<opt>]

and the type specified for ident in the declaration `` T D '' is `` "derived-declarator-type-list T" ,'' then the type specified for ident is `` derived-declarator-type-list array of T .''/60/    If the size is not present, the array type is an incomplete type. 

   For two array types to be compatible, both shall have compatible element types, and if both size specifiers are present, they shall have the same value. 

Examples

         float fa[11], *afp[17];

declares an array of float numbers and an array of pointers to float numbers. 

   Note the distinction between the declarations

         extern int *x;

         extern int y[];

The first declares x to be a pointer to int ; the second declares y to be an array of int of unspecified size (an incomplete type), the storage for which is defined elsewhere. 

Forward references: function definitions ($3.7.1), initialization ($3.5.7). 

3.5.4.3 Function declarators (including prototypes)

Constraints

   A function declarator shall not specify a return type that is a function type or an array type. 

   The only storage-class specifier that shall occur in a parameter declaration is register . 

   An identifier list in a function declarator that is not part of a function definition shall be empty. 

Semantics

   If, in the declaration `` T D1 ,'' D1 has the form

         D( parameter-type-list)

         D( identifier-list<opt>)

and the type specified for ident in the declaration `` T D '' is `` "derived-declarator-type-list T" ,'' then the type specified for ident is `` derived-declarator-type-list function returning T .''

   A parameter type list specifies the types of, and may declare identifiers for, the parameters of the function.  If the list terminates with an ellipsis ( , ... ), no information about the number or types of the parameters after the comma is supplied./61/    The special case of void as the only item in the list specifies that the function has no parameters. 

   In a parameter declaration, a single typedef name in parentheses is taken to be an abstract declarator that specifies a function with a single parameter, not as redundant parentheses around the identifier for a declarator. 

   The storage-class specifier in the declaration specifiers for a parameter declaration, if present, is ignored unless the declared parameter is one of the members of the parameter type list for a function definition. 

   An identifier list declares only the identifiers of the parameters of the function.  An empty list in a function declarator that is part of a function definition specifies that the function has no parameters.  The empty list in a function declarator that is not part of a function definition specifies that no information about the number or types of the parameters is supplied./62/   

   For two function types to be compatible, both shall specify compatible return types./63/    Moreover, the parameter type lists, if both are present, shall agree in the number of parameters and in use of the ellipsis terminator; corresponding parameters shall have compatible types.  If one type has a parameter type list and the other type is specified by a function declarator that is not part of a function definition and that contains an empty identifier list, the parameter list shall not have an ellipsis terminator and the type of each parameter shall be compatible with the type that results from the application of the default argument promotions.  If one type has a parameter type list and the other type is specified by a function definition that contains a (possibly empty) identifier list, both shall agree in the number of parameters, and the type of each prototype parameter shall be compatible with the type that results from the application of the default argument promotions to the type of the corresponding identifier. (For each parameter declared with function or array type, its type for these comparisons is the one that results from conversion to a pointer type, as in $3.7.1.  For each parameter declared with qualified type, its type for these comparisons is the unqualified version of its declared type.)

Examples

   The declaration

         int f(void), *fip(), (*pfi)();

declares a function f with no parameters returning an int , a function fip with no parameter specification returning a pointer to an int , and a pointer pfi to a function with no parameter specification returning an int .  It is especially useful to compare the last two.  The binding of *fip() is *(fip()) , so that the declaration suggests, and the same construction in an expression requires, the calling of a function fip , and then using indirection through the pointer result to yield an int .  In the declarator (*pfi)() , the extra parentheses are necessary to indicate that indirection through a pointer to a function yields a function designator, which is then used to call the function; it returns an int . 

   If the declaration occurs outside of any function, the identifiers have file scope and external linkage.  If the declaration occurs inside a function, the identifiers of the functions f and fip have block scope and external linkage, and the identifier of the pointer pfi has block scope and no linkage. 

   Here are two more intricate examples. 

         int (*apfi[3])(int *x, int *y);

declares an array apfi of three pointers to functions returning int .  Each of these functions has two parameters that are pointers to int .  The identifiers x and y are declared for descriptive purposes only and go out of scope at the end of the declaration of apfi. The declaration

         int (*fpfi(int (*)(long), int))(int, ...);

declares a function fpfi that returns a pointer to a function returning an int .  The function fpfi has two parameters: a pointer to a function returning an int (with one parameter of type long ), and an int . The pointer returned by fpfi points to a function that has at least one parameter, which has type int . 

Forward references: function definitions ($3.7.1), type names ($3.5.5). 

3.5.5 Type names

Syntax

          type-name:

                  specifier-qualifier-list abstract-declarator<opt>

          abstract-declarator:

                  pointer

                  pointer<opt> direct-abstract-declarator

          direct-abstract-declarator:

                  (  abstract-declarator )

                  direct-abstract-declarator<opt> [  constant-expression<opt> ]

                  direct-abstract-declarator<opt> (  parameter-type-list<opt> )

Semantics

   In several contexts it is desired to specify a type.  This is accomplished using a type name  ,which is syntactically a declaration for a function or an object of that type that omits the identifier./64/   

Examples

   The constructions

         (a)      int

         (b)      int *

         (c)      int *[3]

         (d)      int (*)[3]

         (e)      int *()

         (f)      int (*)(void)

         (g)      int (*const [])(unsigned int, ...)

name respectively the types (a) int , (b) pointer to int , (c) array of three pointers to int , (d) pointer to an array of three int s, (e) function with no parameter specification returning a pointer to int , (f) pointer to function with no parameters returning an int , and (g) array of an unspecified number of constant pointers to functions, each with one parameter that has type unsigned int and an unspecified number of other parameters, returning an int . 

3.5.6 Type definitions

Syntax

          typedef-name:

                  identifier

Semantics

   In a declaration whose storage-class specifier is typedef , each declarator defines an identifier to be a typedef name that specifies the type specified for the identifier in the way described in $3.5.4.  A typedef declaration does not introduce a new type, only a synonym for the type so specified.  That is, in the following declarations:

         typedef T type_ident;

         type_ident D;

type_ident is defined as a typedef name with the type specified by the declaration specifiers in T (known as T ), and the identifier in D has the type `` "derived-declarator-type-list T" '' where the derived-declarator-type-list is specified by the declarators of D .  A typedef name shares the same name space as other identifiers declared in ordinary declarators.  If the identifier is redeclared in an inner scope or is declared as a member of a structure or union in the same or an inner scope, the type specifiers shall not be omitted in the inner declaration. 

Examples

   After

         typedef int MILES, KLICKSP();

         typedef struct { double re, im; } complex;

the constructions

         MILES distance;

         extern KLICKSP *metricp;

         complex x;

         complex z, *zp;

are all valid declarations.  The type of distance is int , that of metricp is ``pointer to function with no parameter specification returning int ,'' and that of x and z is the specified structure; zp is a pointer to such a structure.  The object distance has a type compatible with any other int object. 

   After the declarations

         typedef struct s1 { int x; } t1, *tp1;

         typedef struct s2 { int x; } t2, *tp2;

type t1 and the type pointed to by tp1 are compatible.  Type t1 is also compatible with type struct s1 , but not compatible with the types struct s2 , t2 , the type pointed to by tp2 , and int . 

   The following constructions

         typedef signed int t;

         typedef int plain;

         struct tag {

                  unsigned t:4;

                  const t:5;

                  plain r:5;

         };

declare a typedef name t with type signed int , a typedef name plain with type int , and a structure with three bit-field members, one named t that contains values in the range [0,15], an unnamed const-qualified bit-field which (if it could be accessed) would contain values in at least the range [-15,+15], and one named r that contains values in the range [0,31] or values in at least the range [-15,+15].  (The choice of range is implementation-defined.) If these declarations are followed in an inner scope by

         t f(t (t));

         long t;

then a function f is declared with type ``function returning signed int with one unnamed parameter with type pointer to function returning signed int with one unnamed parameter with type signed int ,'' and an identifier t with type long . 

3.5.7 Initialization

Syntax

          initializer:

                  assignment-expression

                  {  initializer-list }

                  {  initializer-list , }

          initializer-list:

                  initializer

                  initializer-list ,  initializer

Constraints

   There shall be no more initializers in an initializer list than there are objects to be initialized. 

   The type of the entity to be initialized shall be an object type or an array of unknown size. 

   All the expressions in an initializer for an object that has static storage duration or in an initializer list for an object that has aggregate or union type shall be constant expressions. 

   If the declaration of an identifier has block scope, and the identifier has external or internal linkage, there shall be no initializer for the identifier. 

Semantics

   An initializer specifies the initial value stored in an object. 

   All unnamed structure or union members are ignored during initialization. 

   If an object that has static storage duration is not initialized explicitly, it is initialized implicitly as if every member that has arithmetic type were assigned 0 and every member that has pointer type were assigned a null pointer constant.  If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate./65/

   The initializer for a scalar shall be a single expression, optionally enclosed in braces.  The initial value of the object is that of the expression; the same type constraints and conversions as for simple assignment apply. 

   A brace-enclosed initializer for a union object initializes the member that appears first in the declaration list of the union type. 

   The initializer for a structure or union object that has automatic storage duration either shall be an initializer list as described below, or shall be a single expression that has compatible structure or union type.  In the latter case, the initial value of the object is that of the expression. 

   The rest of this section deals with initializers for objects that have aggregate or union type. 

   An array of character type may be initialized by a character string literal, optionally enclosed in braces.  Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the members of the array. 

   An array with element type compatible with wchar_t may be initialized by a wide string literal, optionally enclosed in braces.  Successive codes of the wide string literal (including the terminating zero-valued code if there is room or if the array is of unknown size) initialize the members of the array. 

   Otherwise, the initializer for an object that has aggregate type shall be a brace-enclosed list of initializers for the members of the aggregate, written in increasing subscript or member order; and the initializer for an object that has union type shall be a brace-enclosed initializer for the first member of the union. 

   If the aggregate contains members that are aggregates or unions, or if the first member of a union is an aggregate or union, the rules apply recursively to the subaggregates or contained unions.  If the initializer of a subaggregate or contained union begins with a left brace, the initializers enclosed by that brace and its matching right brace initialize the members of the subaggregate or the first member of the contained union.  Otherwise, only enough initializers from the list are taken to account for the members of the first subaggregate or the first member of the contained union; any remaining initializers are left to initialize the next member of the aggregate of which the current subaggregate or contained union is a part. 

   If there are fewer initializers in a list than there are members of an aggregate, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration. 

   If an array of unknown size is initialized, its size is determined by the number of initializers provided for its members.  At the end of its initializer list, the array no longer has incomplete type. 

Examples

   The declaration

         int x[] = { 1, 3, 5 };

defines and initializes x as a one-dimensional array object that has three members, as no size was specified and there are three initializers. 

         float y[4][3] = {

                  { 1, 3, 5 },

                  { 2, 4, 6 },

                  { 3, 5, 7 },

         };

is a definition with a fully bracketed initialization: 1, 3, and 5 initialize the first row of the array object y[0] , namely y[0][0] , y[0][1] , and y[0][2] .  Likewise the next two lines initialize y[1] and y[2] .  The initializer ends early, so y[3] is initialized with zeros.  Precisely the same effect could have been achieved by

         float y[4][3] = {

                  1, 3, 5, 2, 4, 6, 3, 5, 7

         };

The initializer for y[0] does not begin with a left brace, so three items from the list are used.  Likewise the next three are taken successively for y[1] and y[2] .  Also,

         float z[4][3] = {

                  { 1 }, { 2 }, { 3 }, { 4 }

         };

initializes the first column of z as specified and initializes the rest with zeros. 

         struct { int a[3], b; } w[] = { { 1 }, 2 };

is a definition with an inconsistently bracketed initialization.  It defines an array with two member structures: w[0].a[0] is 1 and w[1].a[0] is 2; all the other elements are zero. 

   The declaration

         short q[4][3][2] = {

                  { 1 },

                  { 2, 3 },

                  { 4, 5, 6 }

         };

contains an incompletely but consistently bracketed initialization.  It defines a three-dimensional array object: q[0][0][0] is 1, q[1][0][0] is 2, q[1][0][1] is 3, and 4, 5, and 6 initialize q[2][0][0] , q[2][0][1] , and q[2][1][0] , respectively; all the rest are zero.  The initializer for q[0][0][0] does not begin with a left brace, so up to six items from the current list may be used.  There is only one, so the values for the remaining five members are initialized with zero.  Likewise, the initializers for q[1][0][0] and q[2][0][0] do not begin with a left brace, so each uses up to six items, initializing their respective two-dimensional subaggregates.  If there had been more than six items in any of the lists, a diagnostic message would occur.  The same initialization result could have been achieved by:

         short q[4][3][2] = {

                  1, 0, 0, 0, 0, 0,

                  2, 3, 0, 0, 0, 0,

                  4, 5, 6

         };

or by:

         short q[4][3][2] = {

                  {

                           { 1 },

                  },

                  {

                           { 2, 3 },

                  },

                  {

                           { 4, 5 },

                           { 6 },

                  }

         };

in a fully-bracketed form. 

   Note that the fully-bracketed and minimally-bracketed forms of initialization are, in general, less likely to cause confusion. 

   Finally, the declaration

         char s[] = "abc", t[3] = "abc";

defines ``plain'' char array objects s and t whose members are initialized with character string literals.  This declaration is identical to

         char s[] = { 'a', 'b', 'c', '\0' },

              t[] = { 'a', 'b', 'c' };

The contents of the arrays are modifiable.  On the other hand, the declaration

         char *p = "abc";

defines p with type ``pointer to char '' that is initialized to point to an object with type ``array of char '' whose members are initialized with a character string literal.  If an attempt is made to use p to modify the contents of the array, the behavior is undefined. 

Forward references: common definitions <stddef.h> ($4.1.5).

3.6 STATEMENTS

Syntax

          statement:

                  labeled-statement

                  compound-statement

                  expression-statement

                  selection-statement

                  iteration-statement

                  jump-statement

Semantics

   A statement specifies an action to be performed.  Except as indicated, statements are executed in sequence. 

   A full expression is an expression that is not part of another expression.  Each of the following is a full expression: an initializer; the expression in an expression statement; the controlling expression of a selection statement ( if or switch ); the controlling expression of a while or do statement; each of the three expressions of a for statement; the expression in a return statement.  The end of a full expression is a sequence point. 

Forward references: expression and null statements ($3.6.3), selection statements ($3.6.4), iteration statements ($3.6.5), the return statement ($3.6.6.4). 

3.6.1 Labeled statements

Syntax

          labeled-statement:

                  identifier :  statement

                  case  constant-expression :  statement

                  default :  statement

Constraints

   A case or default label shall appear only in a switch statement.  Further constraints on such labels are discussed under the switch statement. 

Semantics

   Any statement may be preceded by a prefix that declares an identifier as a label name.  Labels in themselves do not alter the flow of control, which continues unimpeded across them. 

Forward references: the goto statement ($3.6.6.1), the switch statement ($3.6.4.2). 

3.6.2 Compound statement, or block

Syntax

          compound-statement:

                  {  declaration-list<opt> statement-list<opt> }

          declaration-list:

                  declaration

                  declaration-list declaration

          statement-list:

                  statement

                  statement-list statement

Semantics

   A compound statement (also called a block  )allows a set of statements to be grouped into one syntactic unit, which may have its own set of declarations and initializations (as discussed in $3.1.2.4).  The initializers of objects that have automatic storage duration are evaluated and the values are stored in the objects in the order their declarators appear in the translation unit. 

3.6.3 Expression and null statements

Syntax

          expression-statement:

                  expression<opt> ;

Semantics

   The expression in an expression statement is evaluated as a void expression for its side effects./66/

   A null statement (consisting of just a semicolon) performs no operations. 

Examples

   If a function call is evaluated as an expression statement for its side effects only, the discarding of its value may be made explicit by converting the expression to a void expression by means of a cast:

         int p(int);

         /*...*/

         (void)p(0);

   In the program fragment

         char *s;

         /*...*/

         while (*s++ != '\0')

                  ;

a null statement is used to supply an empty loop body to the iteration statement. 

   A null statement may also be used to carry a label just before the closing } of a compound statement. 

         while (loop1) {

                  /*...*/

                  while (loop2) {

                           /*...*/

                           if (want_out)

                                    goto end_loop1;

                           /*...*/

                  }

                  /*...*/

         end_loop1: ;

         }

Forward references: iteration statements ($3.6.5). 

3.6.4 Selection statements

Syntax

          selection-statement:

                  if (  expression )  statement

                  if (  expression )  statement else  statement

                  switch (  expression )  statement

Semantics

   A selection statement selects among a set of statements depending on the value of a controlling expression. 

3.6.4.1 The if statement

Constraints

   The controlling expression of an if statement shall have scalar type. 

Semantics

   In both forms, the first substatement is executed if the expression compares unequal to 0.  In the else form, the second substatement is executed if the expression compares equal to 0.  If the first substatement is reached via a label, the second substatement is not executed. 

   An else is associated with the lexically immediately preceding else -less if that is in the same block (but not in an enclosed block). 

3.6.4.2 The switch statement

Constraints

   The controlling expression of a switch statement shall have integral type.  The expression of each case label shall be an integral constant expression.  No two of the case constant expressions in the same switch statement shall have the same value after conversion.  There may be at most one default label in a switch statement.  (Any enclosed switch statement may have a default label or case constant expressions with values that duplicate case constant expressions in the enclosing switch statement.)

Semantics

   A switch statement causes control to jump to, into, or past the statement that is the switch body  ,depending on the value of a controlling expression, and on the presence of a default label and the values of any case labels on or in the switch body.  A case or default label is accessible only within the closest enclosing switch statement. 

   The integral promotions are performed on the controlling expression.  The constant expression in each case label is converted to the promoted type of the controlling expression.  If a converted value matches that of the promoted controlling expression, control jumps to the statement following the matched case label.  Otherwise, if there is a default label, control jumps to the labeled statement.  If no converted case constant expression matches and there is no default label, no part of the switch body is executed. 

"Implementation limits"

   As discussed previously ($2.2.4.1), the implementation may limit the number of case values in a switch statement. 

3.6.5 Iteration statements

Syntax

          iteration-statement:

                  while (  expression )  statement

                  do  statement while (  expression ) ;

                  for (  expression<opt> ;  expression<opt> ;  expression<opt> )  statement

Constraints

   The controlling expression of an iteration statement shall have scalar type. 

Semantics

   An iteration statement causes a statement called the loop body to be executed repeatedly until the controlling expression compares equal to 0. 

3.6.5.1 The while statement

   The evaluation of the controlling expression takes place before each execution of the loop body. 

3.6.5.2 The do statement

   The evaluation of the controlling expression takes place after each execution of the loop body. 

3.6.5.3 The for statement

   Except for the behavior of a continue statement in the loop body, the statement

         for (  expression-1 ;  expression-2 ;  expression-3 )  statement

and the sequence of statements

          expression-1 ;

         while ( expression-2) {

                   statement

                  expression-3 ;

         }

are equivalent./67/ expression-1 expression-2 , expression-3

   Both expression-1 and expression-3 may be omitted.  Each is evaluated as a void expression.  An omitted expression-2 is replaced by a nonzero constant. 

Forward references: the continue statement ($3.6.6.2). 

3.6.6 Jump statements

Syntax

          jump-statement:

                  goto  identifier ;

                  continue ;

                  break ;

                  return  expression<opt> ;

Semantics

   A jump statement causes an unconditional jump to another place. 

3.6.6.1 The goto statement

Constraints

   The identifier in a goto statement shall name a label located somewhere in the current function. 

Semantics

A goto statement causes an unconditional jump to the statement prefixed by the named label in the current function. 

3.6.6.2 The continue statement

Constraints

   A continue statement shall appear only in or as a loop body. 

Semantics

   A continue statement causes a jump to the loop-continuation portion of the smallest enclosing iteration statement; that is, to the end of the loop body.  More precisely, in each of the statements

         while (/*...*/) { do {     for (/*...*/) {

           /*...*/           /*...*/           /*...*/

           continue;         continue;         continue;

           /*...*/           /*...*/           /*...*/

         contin: ;         contin: ;         contin: ;

         }        } while (/*...*/);         }

unless the continue statement shown is in an enclosed iteration statement (in which case it is interpreted within that statement), it is equivalent to goto contin; ./68/

3.6.6.3 The break statement

Constraints

   A break statement shall appear only in or as a switch body or loop body. 

Semantics

   A break statement terminates execution of the smallest enclosing switch or iteration statement. 

3.6.6.4 The return statement

Constraints

   A return statement with an expression shall not appear in a function whose return type is void . 

Semantics

   A return statement terminates execution of the current function and returns control to its caller.  A function may have any number of return statements, with and without expressions. 

   If a return statement with an expression is executed, the value of the expression is returned to the caller as the value of the function call expression.  If the expression has a type different from that of the function in which it appears, it is converted as if it were assigned to an object of that type. 

   If a return statement without an expression is executed, and the value of the function call is used by the caller, the behavior is undefined.  Reaching the } that terminates a function is equivalent to executing a return statement without an expression. 

3.7 EXTERNAL DEFINITIONS

Syntax

          translation-unit:

                  external-declaration

                  translation-unit external-declaration

          external-declaration:

                  function-definition

                  declaration

Constraints

   The storage-class specifiers auto and register shall not appear in the declaration specifiers in an external declaration. 

   There shall be no more than one external definition for each identifier declared with internal linkage in a translation unit.  Moreover, if an identifier declared with internal linkage is used in an expression (other than as a part of the operand of a sizeof operator), there shall be exactly one external definition for the identifier in the translation unit. 

Semantics

   As discussed in $2.1.1.1, the unit of program text after preprocessing is a translation unit, which consists of a sequence of external declarations.  These are described as ``external'' because they appear outside any function (and hence have file scope).  As discussed in $3.5, a declaration that also causes storage to be reserved for an object or a function named by the identifier is a definition. 

   An external definition is an external declaration that is also a definition of a function or an object.  If an identifier declared with external linkage is used in an expression (other than as part of the operand of a sizeof operator), somewhere in the entire program there shall be exactly one external definition for the identifier./69/

3.7.1 Function definitions

Syntax

          function-definition:

                  declaration-specifiers<opt> declarator declaration-list<opt> compound-statement

Constraints

   The identifier declared in a function definition (which is the name of the function) shall have a function type, as specified by the declarator portion of the function definition./70/

   The return type of a function shall be void or an object type other than array. 

   The storage-class specifier, if any, in the declaration specifiers shall be either extern or static . 

   If the declarator includes a parameter type list, the declaration of each parameter shall include an identifier (except for the special case of a parameter list consisting of a single parameter of type void , in which there shall not be an identifier).  No declaration list shall follow. 

   If the declarator includes an identifier list, only the identifiers it names shall be declared in the declaration list.  An identifier declared as a typedef name shall not be redeclared as a parameter.  The declarations in the declaration list shall contain no storage-class specifier other than register and no initializations. 

Semantics

   The declarator in a function definition specifies the name of the function being defined and the identifiers of its parameters.  If the declarator includes a parameter type list, the list also specifies the types of all the parameters; such a declarator also serves as a function prototype for later calls to the same function in the same translation unit.  If the declarator includes an identifier list,/71/ the types of the parameters may be declared in a following declaration list.  Any parameter that is not declared has type int . 

   If a function that accepts a variable number of arguments is defined without a parameter type list that ends with the ellipsis notation, the behavior is undefined. 

   On entry to the function the value of each argument expression shall be converted to the type of its corresponding parameter, as if by assignment to the parameter.  Array expressions and function designators as arguments are converted to pointers before the call.  A declaration of a parameter as ``array of type '' shall be adjusted to ``pointer to type ,'' and a declaration of a parameter as ``function returning type '' shall be adjusted to ``pointer to function returning type ,'' as in $3.2.2.1.  The resulting parameter type shall be an object type. 

   Each parameter has automatic storage duration.  Its identifier is an lvalue./72/    The layout of the storage for parameters is unspecified. 

Examples

         extern int max(int a, int b)

         {

                  return a > b ? a : b;

         }

Here extern is the storage-class specifier and int is the type specifier (each of which may be omitted as those are the defaults); max(int a, int b) is the function declarator; and

         { return a > b ? a : b; }

is the function body.  The following similar definition uses the identifier-list form for the parameter declarations:

         extern int max(a, b)

         int a, b;

         {

                  return a > b ? a : b;

         }

Here int a, b; is the declaration list for the parameters, which may be omitted because those are the defaults. The difference between these two definitions is that the first form acts as a prototype declaration that forces conversion of the arguments of subsequent calls to the function, whereas the second form may not. 

   To pass one function to another, one might say

                  int f(void);

                  /*...*/

                  g(f);

Note that f must be declared explicitly in the calling function, as its appearance in the expression g(f) was not followed by ( .  Then the definition of g might read

         g(int (*funcp)(void))

         {

                  /*...*/ (*funcp)() /*  or funcp() ... */

         }

or, equivalently,

         g(int func(void))

         {

                  /*...*/ func() /*  or (*func)() ... */

         }

3.7.2 External object definitions

Semantics

   If the declaration of an identifier for an object has file scope and an initializer, the declaration is an external definition for the identifier. 

   A declaration of an identifier for an object that has file scope without an initializer, and without a storage-class specifier or with the storage-class specifier static , constitutes a tentative definition  .If a translation unit contains one or more tentative definitions for an identifier, and the translation unit contains no external definition for that identifier, then the behavior is exactly as if the translation unit contains a file scope declaration of that identifier, with the composite type as of the end of the translation unit, with an initializer equal to 0. 

   If the declaration of an identifier for an object is a tentative definition and has internal linkage, the declared type shall not be an incomplete type. 

Examples

        int i1 = 1;                         /*  definition, external linkage */

         static int i2 = 2;         /*  definition, internal linkage */

         extern int i3 = 3;         /*  definition, external linkage */

         int i4;                    /*  tentative definition, external linkage */

         static int i5;             /*  tentative definition, internal linkage */

         int i1;           /*  valid tentative definition, refers to previous */

         int i2;           /*  $3.1.2.2 renders undefined, linkage disagreement */

         int i3;           /*  valid tentative definition, refers to previous */

         int i4;           /*  valid tentative definition, refers to previous */

         int i5;           /*  $3.1.2.2 renders undefined, linkage disagreement */

         extern int i1;    /*  refers to previous, whose linkage is external */

         extern int i2;    /*  refers to previous, whose linkage is internal */

         extern int i3;    /*  refers to previous, whose linkage is external */

         extern int i4;    /*  refers to previous, whose linkage is external */

         extern int i5;    /*  refers to previous, whose linkage is internal */

3.8 PREPROCESSING DIRECTIVES

Syntax

          preprocessing-file:

                  group<opt>

          group:

                  group-part

                  group group-part

          group-part:

                  pp-tokens<opt> new-line

                  if-section

                  control-line

          if-section:

                  if-group elif-groups<opt> else-group<opt> endif-line

          if-group:

                  # if      constant-expression new-line group<opt>

                  # ifdef   identifier new-line group<opt>

                  # ifndef  identifier new-line group<opt>

          elif-groups:

                  elif-group

                  elif-groups elif-group

          elif-group:

                  # elif    constant-expression new-line group<opt>

          else-group:

                  # else    new-line group<opt>

          endif-line:

                  # endif   new-line

          control-line:

                  # include  pp-tokens new-line

                  # define   identifier replacement-list new-line

                  # define   identifier lparen identifier-list<opt> )  replacement-list new-line

                  # undef    identifier new-line

                  # line     pp-tokens new-line

                  # error    pp-tokens<opt> new-line

                  # pragma   pp-tokens<opt> new-line

                  #          new-line

          lparen:

                  the left-parenthesis character without preceding white-space

          replacement-list:

                  pp-tokens<opt>

          pp-tokens:

                  preprocessing-token

                  pp-tokens preprocessing-token

          new-line:

                  the new-line character

Description

   A preprocessing directive consists of a sequence of preprocessing tokens that begins with a # preprocessing token that is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character, and is ended by the next new-line character./73/

Constraints

   The only white-space characters that shall appear between preprocessing tokens within a preprocessing directive (from just after the introducing # preprocessing token through just before the terminating new-line character) are space and horizontal-tab (including spaces that have replaced comments in translation phase 3). 

Semantics

   The implementation can process and skip sections of source files conditionally, include other source files, and replace macros. These capabilities are called preprocessing , because conceptually they occur before translation of the resulting translation unit. 

   The preprocessing tokens within a preprocessing directive are not subject to macro expansion unless otherwise stated. 

3.8.1 Conditional inclusion

Constraints

   The expression that controls conditional inclusion shall be an integral constant expression except that: it shall not contain a cast; identifiers (including those lexically identical to keywords) are interpreted as described below;/74/ and it may contain unary operator expressions of the form

         defined  identifier

         defined (  identifier )

which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is predefined or if it has been the subject of a #define preprocessing directive without an intervening #undef directive with the same subject identifier), 0 if it is not. 

   Each preprocessing token that remains after all macro replacements have occurred shall be in the lexical form of a token. 

Semantics

   Preprocessing directives of the forms

         # if    constant-expression new-line group<opt>

         # elif  constant-expression new-line group<opt>

check whether the controlling constant expression evaluates to nonzero. 

   Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified by the defined unary operator), just as in normal text.  If the token defined is generated as a result of this replacement process, the behavior is undefined.  After all replacements are finished, the resulting preprocessing tokens are converted into tokens, and then all remaining identifiers are replaced with 0 .  The resulting tokens comprise the controlling constant expression which is evaluated according to the rules of $3.4 using arithmetic that has at least the ranges specified in $2.2.4.2, except that int and unsigned int act as if they have the same representation as, respectively, long and unsigned long .  This includes interpreting character constants, which may involve converting escape sequences into execution character set members.  Whether the numeric value for these character constants matches the value obtained when an identical character constant occurs in an expression (other than within a #if or #elif directive) is implementation-defined./75/

Also, whether a single-character character constant may have a negative value is implementation-defined. 

   Preprocessing directives of the forms

         # ifdef   identifier new-line group<opt>

         # ifndef  identifier new-line group<opt>

check whether the identifier is or is not currently defined as a macro name.  Their conditions are equivalent to #if defined identifier and #if !defined identifier respectively. 

   Each directive's condition is checked in order.  If it evaluates to false (zero), the group that it controls is skipped: directives are processed only through the name that determines the directive in order to keep track of the level of nested conditionals; the rest of the directives' preprocessing tokens are ignored, as are the other preprocessing tokens in the group.  Only the first group whose control condition evaluates to true (nonzero) is processed.  If none of the conditions evaluates to true, and there is a #else directive, the group controlled by the #else is processed; lacking a #else directive, all the groups until the #endif are skipped./76/   

Forward references: macro replacement ($3.8.3), source file inclusion ($3.8.2). 

3.8.2 Source file inclusion

Constraints

   A #include directive shall identify a header or source file that can be processed by the implementation. 

Semantics

   A preprocessing directive of the form

         # include < h-char-sequence>  new-line

searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header.  How the places are specified or the header identified is implementation-defined. 

   A preprocessing directive of the form

         # include " q-char-sequence"  new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the  delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read

         # include < h-char-sequence>  new-line

with the identical contained sequence (including > characters, if any) from the original directive. 

   A preprocessing directive of the form

         # include  pp-tokens new-line

(that does not match one of the two previous forms) is permitted.  The preprocessing tokens after include in the directive are processed just as in normal text.  (Each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens.)  The directive resulting after all replacements shall match one of the two previous forms./77/    The method by which a sequence of preprocessing tokens between a < and a > preprocessing token pair or a pair of  characters is combined into a single header name preprocessing token is implementation-defined. 

   There shall be an implementation-defined mapping between the delimited sequence and the external source file name.  The implementation shall provide unique mappings for sequences consisting of one or more letters (as defined in $2.2.1) followed by a period ( . ) and a single letter.  The implementation may ignore the distinctions of alphabetical case and restrict the mapping to six significant characters before the period. 

   A #include preprocessing directive may appear in a source file that has been read because of a #include directive in another file, up to an implementation-defined nesting limit (see $2.2.4.1). 

Examples

   The most common uses of #include preprocessing directives are as in the following:

         #include <stdio.h>

         #include "myprog.h"

   This example illustrates a macro-replaced #include directive:

         #if VERSION =^= 1

                  #define INCFILE  "vers1.h"

         #elif VERSION =^= 2

                  #define INCFILE  "vers2.h"

                                              /*  and so on */

         #else

                  #define INCFILE  "versN.h"

         #endif

         /*...*/

         #include INCFILE

Forward references: macro replacement ($3.8.3). 

3.8.3 Macro replacement

Constraints

   Two replacement lists are identical if and only if the preprocessing tokens in both have the same number, ordering, spelling, and white-space separation, where all white-space separations are considered identical. 

   An identifier currently defined as a macro without use of lparen (an object-like macro) may be redefined by another #define preprocessing directive provided that the second definition is an object-like macro definition and the two replacement lists are identical. 

   An identifier currently defined as a macro using lparen (a function-like macro) may be redefined by another #define preprocessing directive provided that the second definition is a function-like macro definition that has the same number and spelling of parameters, and the two replacement lists are identical. 

   The number of arguments in an invocation of a function-like macro shall agree with the number of parameters in the macro definition, and there shall exist a ) preprocessing token that terminates the invocation. 

   A parameter identifier in a function-like macro shall be uniquely declared within its scope. 

Semantics

   The identifier immediately following the define is called the macro name  .Any white-space characters preceding or following the replacement list of preprocessing tokens are not considered part of the replacement list for either form of macro. 

   If a # preprocessing token, followed by an identifier, occurs lexically at the point at which a preprocessing directive could begin, the identifier is not subject to macro replacement. 

   A preprocessing directive of the form

         # define  identifier replacement-list new-line

defines an object-like macro that causes each subsequent instance of the macro name/78/ to be replaced by the replacement list of preprocessing tokens that constitute the remainder of the directive.  The replacement list is then rescanned for more macro names as specified below. 

   A preprocessing directive of the form

         # define  identifier lparen identifier-list<opt> )  replacement-list new-line

defines a function-like macro with arguments, similar syntactically to a function call.  The parameters are specified by the optional list of identifiers, whose scope extends from their declaration in the identifier list until the new-line character that terminates the #define preprocessing directive.  Each subsequent instance of the function-like macro name followed by a ( as the next preprocessing token introduces the sequence of preprocessing tokens that is replaced by the replacement list in the definition (an invocation of the macro).  The replaced sequence of preprocessing tokens is terminated by the matching ) preprocessing token, skipping intervening matched pairs of left and right parenthesis preprocessing tokens.  Within the sequence of preprocessing tokens making up an invocation of a function-like macro, new-line is considered a normal white-space character. 

   The sequence of preprocessing tokens bounded by the outside-most matching parentheses forms the list of arguments for the function-like macro.  The individual arguments within the list are separated by comma preprocessing tokens, but comma preprocessing tokens bounded by nested parentheses do not separate arguments.  If (before argument substitution) any argument consists of no preprocessing tokens, the behavior is undefined.  If there are sequences of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives, the behavior is undefined. 

3.8.3.1 Argument substitution

   After the arguments for the invocation of a function-like macro have been identified, argument substitution takes place.  A parameter in the replacement list, unless preceded by a # or ## preprocessing token or followed by a ## preprocessing token (see below), is replaced by the corresponding argument after all macros contained therein have been expanded.  Before being substituted, each argument's preprocessing tokens are completely macro replaced as if they formed the rest of the source file; no other preprocessing tokens are available. 

3.8.3.2 The # operator

Constraints

   Each # preprocessing token in the replacement list for a function-like macro shall be followed by a parameter as the next preprocessing token in the replacement list. 

Semantics

   If, in the replacement list, a parameter is immediately preceded by a # preprocessing token, both are replaced by a single character string literal preprocessing token that contains the spelling of the preprocessing token sequence for the corresponding argument.  Each occurrence of white space between the argument's preprocessing tokens becomes a single space character in the character string literal.  White space before the first preprocessing token and after the last preprocessing token comprising the argument is deleted.  Otherwise, the original spelling of each preprocessing token in the argument is retained in the character string literal, except for special handling for producing the spelling of string literals and character constants: a \ character is inserted before each  and \ character of a character constant or string literal (including the delimiting  characters).  If the replacement that results is not a valid character string literal, the behavior is undefined.  The order of evaluation of # and ## operators is unspecified. 

3.8.3.3 The ## operator

Constraints

   A ## preprocessing token shall not occur at the beginning or at the end of a replacement list for either form of macro definition. 

Semantics

   If, in the replacement list, a parameter is immediately preceded or followed by a ## preprocessing token, the parameter is replaced by the corresponding argument's preprocessing token sequence. 

   For both object-like and function-like macro invocations, before the replacement list is reexamined for more macro names to replace, each instance of a ## preprocessing token in the replacement list (not from an argument) is deleted and the preceding preprocessing token is concatenated with the following preprocessing token.  If the result is not a valid preprocessing token, the behavior is undefined.  The resulting token is available for further macro replacement.  The order of evaluation of ## operators is unspecified. 

3.8.3.4 Rescanning and further replacement

   After all parameters in the replacement list have been substituted, the resulting preprocessing token sequence is rescanned with the rest of the source file's preprocessing tokens for more macro names to replace. 

   If the name of the macro being replaced is found during this scan of the replacement list (not including the rest of the source file's preprocessing tokens), it is not replaced.  Further, if any nested replacements encounter the name of the macro being replaced, it is not replaced.  These nonreplaced macro name preprocessing tokens are no longer available for further replacement even if they are later (re)examined in contexts in which that macro name preprocessing token would otherwise have been replaced. 

   The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one. 

3.8.3.5 Scope of macro definitions

   A macro definition lasts (independent of block structure) until a corresponding #undef directive is encountered or (if none is encountered) until the end of the translation unit. 

   A preprocessing directive of the form

         # undef  identifier new-line

causes the specified identifier no longer to be defined as a macro name.  It is ignored if the specified identifier is not currently defined as a macro name. 

Examples

   The simplest use of this facility is to define a ``manifest constant,'' as in

         #define TABSIZE 100

         int table[TABSIZE];

   The following defines a function-like macro whose value is the maximum of its arguments.  It has the advantages of working for any compatible types of the arguments and of generating in-line code without the overhead of function calling.  It has the disadvantages of evaluating one or the other of its arguments a second time (including side effects) and of generating more code than a function if invoked several times. 

         #define max(a, b) ((a) > (b) ? (a) : (b))

The parentheses ensure that the arguments and the resulting expression are bound properly. 

   To illustrate the rules for redefinition and reexamination, the sequence

         #define x    3

         #define f(a) f(x * (a))

         #undef  x

         #define x    2

         #define g    f

         #define z    z[0]

         #define h    g(~

         #define m(a) a(w)

         #define w    0,1

         #define t(a) a

         f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);

         g(x+(3,4)-w) | h 5) & m

                  (f)^m(m);

results in

         f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);

         f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);

   To illustrate the rules for creating character string literals and concatenating tokens, the sequence

         #define str(s)      # s

         #define xstr(s)     str(s)

         #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \

                                             x ## s, x ## t)

         #define INCFILE(n)  vers ## n  /*  from previous #include  example */

         #define glue(a, b)  a ## b

         #define xglue(a, b) glue(a, b)

         #define HIGHLOW     "hello"

         #define LOW         LOW ", world"

         debug(1, 2);

         fputs(str(strncmp("abc\0d", "abc", '\4')  /* this goes away */

                  =^= 0) str(: @\n), s);

         #include xstr(INCFILE(2).h)

         glue(HIGH, LOW);

         xglue(HIGH, LOW)

results in

         printf("x" "1" "= %d, x" "2" "= %s", x1, x2);

         fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') =^= 0" ": @\n", s);

         #include "vers2.h"     (after macro replacement, before file access)

         "hello";

         "hello" ", world"

or, after concatenation of the character string literals,

         printf("x1= %d, x2= %s", x1, x2);

         fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') =^= 0: @\n", s);

         #include "vers2.h"     (after macro replacement, before file access)

         "hello";

         "hello, world"

Space around the # and ## tokens in the macro definition is optional. 

   And finally, to demonstrate the redefinition rules, the following sequence is valid. 

         #define OBJ_LIKE      (1-1)

         #define OBJ_LIKE      /* white space */ (1-1) /* other */

         #define FTN_LIKE(a)   ( a )

         #define FTN_LIKE( a )(              /* note the white space */ \

                                             a /* other stuff on this line

                                               */ )

But the following redefinitions are invalid:

         #define OBJ_LIKE    (0)     /*  different token sequence */

         #define OBJ_LIKE    (1 - 1) /*  different white space */

         #define FTN_LIKE(b) ( a )   /*  different parameter usage */

         #define FTN_LIKE(b) ( b )   /*  different parameter spelling */

3.8.4 Line control

Constraints

   The string literal of a #line directive, if present, shall be a character string literal. 

Semantics

   The line number of the current source line is one greater than the number of new-line characters read or introduced in translation phase 1 ($2.1.1.2) while processing the source file to the current token. 

   A preprocessing directive of the form

         # line  digit-sequence new-line

causes the implementation to behave as if the following sequence of source lines begins with a source line that has a line number as specified by the digit sequence (interpreted as a decimal integer). 

   A preprocessing directive of the form

         # line  digit-sequence " s-char-sequence<opt>"  new-line

sets the line number similarly and changes the presumed name of the source file to be the contents of the character string literal. 

   A preprocessing directive of the form

         # line  pp-tokens new-line

(that does not match one of the two previous forms) is permitted.  The preprocessing tokens after line on the directive are processed just as in normal text (each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens).  The directive resulting after all replacements shall match one of the two previous forms and is then processed as appropriate. 

3.8.5 Error directive

Semantics

   A preprocessing directive of the form

         # error  pp-tokens<opt> new-line

causes the implementation to produce a diagnostic message that includes the specified sequence of preprocessing tokens. 

3.8.6 Pragma directive

Semantics

   A preprocessing directive of the form

         # pragma  pp-tokens<opt> new-line

causes the implementation to behave in an implementation-defined manner.  Any pragma that is not recognized by the implementation is ignored. 

3.8.7 Null directive

Semantics

   A preprocessing directive of the form

         #  new-line

has no effect. 

3.8.8 Predefined macro names

   The following macro names shall be defined by the implementation: The line number of the current source line (a decimal constant).  The presumed name of the source file (a character string literal).  The date of translation of the source file (a character string literal of the form Mmm dd yyyy , where the names of the months are the same as those generated by the asctime function, and the first character of dd is a space character if the value is less than 10).  If the date of translation is not available, an implementation-defined valid date shall be supplied.  The time of translation of the source file (a character string literal of the form hh:mm:ss as in the time generated by the asctime function).  If the time of translation is not available, an implementation-defined valid time shall be supplied.  the decimal constant 1./79/   

   The values of the predefined macros (except for __LINE__ and __FILE__ ) remain constant throughout the translation unit. 

   None of these macro names, nor the identifier defined , shall be the subject of a #define or a #undef preprocessing directive.  All predefined macro names shall begin with a leading underscore followed by an upper-case letter or a second underscore. 

Forward references: the asctime function ($4.12.3.1). 

3.9 FUTURE LANGUAGE DIRECTIONS

3.9.1 External names

   Restriction of the significance of an external name to fewer than 31 characters or to only one case is an obsolescent feature that is a concession to existing implementations. 

3.9.2 Character escape sequences

   Lower-case letters as escape sequences are reserved for future standardization.  Other characters may be used in extensions. 

3.9.3 Storage-class specifiers

   The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature. 

3.9.4 Function declarators

   The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature. 

3.9.5 Function definitions

   The use of function definitions with separate parameter identifier and declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature.  is an obsolescent feature. 


[Contents] [Previous] [Next] [Home]

 

NDP77
http://www.ndp77.net
webmaster Massimo F. ARENA
webmaster@ndp77.net