2. ENVIRONMENT

   An implementation translates C source files and executes C programs in two data-processing-system environments, which will be called the translation environment and the execution environment in this Standard.  Their characteristics define and constrain the results of executing conforming C programs constructed according to the syntactic and semantic rules for conforming implementations. 

Forward references: In the environment section ($2), only a few of many possible forward references have been noted. 

2.1 CONCEPTUAL MODELS

2.1.1 Translation environment

2.1.1.1 Program structure

   A C program need not all be translated at the same time.  The text of the program is kept in units called source files in this Standard.  A source file together with all the headers and source files included via the preprocessing directive #include , less any source lines skipped by any of the conditional inclusion preprocessing directives, is called a translation unit  .Previously translated translation units may be preserved individually or in libraries.  The separate translation units of a program communicate by (for example) calls to functions whose identifiers have external linkage, by manipulation of objects whose identifiers have external linkage, and by manipulation of data files.  Translation units may be separately translated and then later linked to produce an executable program. 

Forward references: conditional inclusion ($3.8.1), linkages of identifiers ($3.1.2.2), source file inclusion ($3.8.2). 

2.1.1.2 Translation phases

   The precedence among the syntax rules of translation is specified by the following phases./3/

 1. Physical source file characters are mapped to the source character set (introducing new-line characters for end-of-line indicators) if necessary.  Trigraph sequences are replaced by corresponding single-character internal representations. 

 2. Each instance of a new-line character and an immediately preceding backslash character is deleted, splicing physical source lines to form logical source lines.  A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character. 

 3. The source file is decomposed into preprocessing tokens/4/ and sequences of white-space characters (including comments).  A source file shall not end in a partial preprocessing token or comment.  Each comment is replaced by one space character.  New-line characters are retained.  Whether each nonempty sequence of other white-space characters is retained or replaced by one space character is implementation-defined. 

 4. Preprocessing directives are executed and macro invocations are expanded.  A #include preprocessing directive causes the named header or source file to be processed from phase 1 through phase 4, recursively. 

 5. Each escape sequence in character constants and string literals is converted to a member of the execution character set. 

 6. Adjacent character string literal tokens are concatenated and adjacent wide string literal tokens are concatenated. 

 7. White-space characters separating tokens are no longer significant.  Preprocessing tokens are converted into tokens.  The resulting tokens are syntactically and semantically analyzed and translated. 

 8. All external object and function references are resolved.  Library components are linked to satisfy external references to functions and objects not defined in the current translation.  All such translator output is collected into a program image which contains information needed for execution in its execution environment. 

Forward references: lexical elements ($3.1), preprocessing directives ($3.8), trigraph sequences ($2.2.1.1). 

2.1.1.3 Diagnostics

   A conforming implementation shall produce at least one diagnostic message (identified in an implementation-defined manner) for every translation unit that contains a violation of any syntax rule or constraint.  Diagnostic messages need not be produced in other circumstances. 

2.1.2 Execution environments

   Two execution environments are defined: freestanding and hosted . In both cases, program startup occurs when a designated C function is called by the execution environment.  All objects in static storage shall be initialized (set to their initial values) before program startup.  The manner and timing of such initialization are otherwise unspecified.  Program termination returns control to the execution environment. 

Forward references: initialization ($3.5.7). 

2.1.2.1 Freestanding environment

   In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined.  There are otherwise no reserved external identifiers.  Any library facilities available to a freestanding program are implementation-defined. 

   The effect of program termination in a freestanding environment is implementation-defined.  

2.1.2.2 Hosted environment

   A hosted environment need not be provided, but shall conform to the following specifications if present. 

"Program startup"

   The function called at program startup is named main .  The implementation declares no prototype for this function.  It can be defined with no parameters:

         int main(void) { /*...*/ }

or with two parameters (referred to here as argc and argv , though any names may be used, as they are local to the function in which they are declared):

         int main(int argc, char *argv[]) { /*...*/ }

   If they are defined, the parameters to the main function shall obey the following constraints:

 * The value of argc shall be nonnegative. 

 * argv[argc] shall be a null pointer. 

 * If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup.  The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment.  If the host environment is not capable of supplying strings with letters in both upper-case and lower-case, the implementation shall ensure that the strings are received in lower-case. 

 * If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name  ;argv[0][0] shall be the null character if the program name is not available from the host environment.  If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters  .

 * The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination. 

"Program execution"

   In a hosted environment, a program may use all the functions, macros, type definitions, and objects described in the library section ($4). 

"Program termination"

   A return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument.  If the main function executes a return that specifies no value, the termination status returned to the host environment is undefined. 

Forward references: definition of terms ($4.1.1), the exit function ($4.10.4.3). 

2.1.2.3 Program execution

   The semantic descriptions in this Standard describe the behavior of an abstract machine in which issues of optimization are irrelevant. 

   Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects  ,which are changes in the state of the execution environment.  Evaluation of an expression may produce side effects.  At certain specified points in the execution sequence called sequence points  ,all side effects of previous evaluations shall be complete and no side effects of subsequent evaluations shall have taken place. 

   In the abstract machine, all expressions are evaluated as specified by the semantics.  An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object). 

   When the processing of the abstract machine is interrupted by receipt of a signal, only the values of objects as of the previous sequence point may be relied on.  Objects that may be modified between the previous sequence point and the next sequence point need not have received their correct values yet. 

   An instance of each object with automatic storage duration is associated with each entry into a block.  Such an object exists and retains its last-stored value during the execution of the block and while the block is suspended (by a call of a function or receipt of a signal). 

   The least requirements on a conforming implementation are:

 * At sequence points, volatile objects are stable in the sense that previous evaluations are complete and subsequent evaluations have not yet occurred. 

 * At program termination, all data written into files shall be identical to the result that execution of the program according to the abstract semantics would have produced. 

 * The input and output dynamics of interactive devices shall take place as specified in $4.9.3.  The intent of these requirements is that unbuffered or line-buffered output appear as soon as possible, to ensure that prompting messages actually appear prior to a program waiting for input. 

   What constitutes an interactive device is implementation-defined. 

   More stringent correspondences between abstract and actual semantics may be defined by each implementation. 

"Examples"

   An implementation might define a one-to-one correspondence between abstract and actual semantics: at every sequence point, the values of the actual objects would agree with those specified by the abstract semantics.  The keyword volatile would then be redundant. 

   Alternatively, an implementation might perform various optimizations within each translation unit, such that the actual semantics would agree with the abstract semantics only when making function calls across translation unit boundaries.  In such an implementation, at the time of each function entry and function return where the calling function and the called function are in different translation units, the values of all externally linked objects and of all objects accessible via pointers therein would agree with the abstract semantics.  Furthermore, at the time of each such function entry the values of the parameters of the called function and of all objects accessible via pointers therein would agree with the abstract semantics.  In this type of implementation, objects referred to by interrupt service routines activated by the signal function would require explicit specification of volatile storage, as well as other implementation-defined restrictions. 

   In executing the fragment

         char c1, c2;

         /*...*/

         c1 = c1 + c2;

the ``integral promotions'' require that the abstract machine promote the value of each variable to int size and then add the two int s and truncate the sum.  Provided the addition of two char s can be done without creating an overflow exception, the actual execution need only produce the same result, possibly omitting the promotions. 

   Similarly, in the fragment

         float f1, f2;

         double d;

         /*...*/

         f1 = f2 * d;

the multiplication may be executed using single-precision arithmetic if the implementation can ascertain that the result would be the same as if it were executed using double-precision arithmetic (for example, if d were replaced by the constant 2.0, which has type double ).  Alternatively, an operation involving only int s or float s may be executed using double-precision operations if neither range nor precision is lost thereby. 

Forward references: compound statement, or block ($3.6.2), files ($4.9.3), sequence points ($3.3, $3.6), the signal function ($4.7), type qualifiers ($3.5.3). 

2.2 ENVIRONMENTAL CONSIDERATIONS

2.2.1 Character sets

   Two sets of characters and their associated collating sequences shall be defined: the set in which source files are written, and the set interpreted in the execution environment.  The values of the members of the execution character set are implementation-defined; any additional members beyond those required by this section are locale-specific. 

   In a character constant or string literal, members of the execution character set shall be represented by corresponding members of the source character set or by escape sequences consisting of the backslash \ followed by one or more characters.  A byte with all bits set to 0, called the null character  ,shall exist in the basic execution character set; it is used to terminate a character string literal. 

   Both the basic source and basic execution character sets shall have at least the following members: the 26 upper-case letters of the English alphabet

         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

the 26 lower-case letters of the English alphabet

         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

the 10 decimal digits

         0  1  2  3  4  5  6  7  8  9

the following 29 graphic characters

         !  "  #  %  &  '  (  )  *  +  ,  -  .  /  :

         ;  <  =  >  ?  [  \  ]  ^  _  {  |  }  ~

the space character, and control characters representing horizontal tab, vertical tab, and form feed.  In both the source and execution basic character sets, the value of each character after 0 in the above list of decimal digits shall be one greater than the value of the previous.  In source files, there shall be some way of indicating the end of each line of text; this Standard treats such an end-of-line indicator as if it were a single new-line character.  In the execution character set, there shall be control characters representing alert, backspace, carriage return, and new line.  If any other characters are encountered in a source file (except in a preprocessing token that is never converted to a token, a character constant, a string literal, or a comment), the behavior is undefined. 

Forward references: character constants ($3.1.3.4), preprocessing directives ($3.8), string literals ($3.1.4), comments ($3.1.9).  

2.2.1.1 Trigraph sequences

   All occurrences in a source file of the following sequences of three characters (called trigraph sequences  /5/)are replaced with the corresponding single character. 

         ??=      #

         ??(      [

         ??/      \

         ??)      ]

         ??'      ^

         ??<      {

         ??!      |

         ??>      }

         ??-      ~

No other trigraph sequences exist.  Each ? that does not begin one of the trigraphs listed above is not changed. 

Example

   The following source line

         printf("Eh???/n");

becomes (after replacement of the trigraph sequence ??/ )

         printf("Eh?\n");

2.2.1.2 Multibyte characters

   The source character set may contain multibyte characters, used to represent members of the extended character set.  The execution character set may also contain multibyte characters, which need not have the same encoding as for the source character set.  For both character sets, the following shall hold:

 * The single-byte characters defined in $2.2.1 shall be present. 

 * The presence, meaning, and representation of any additional members is locale-specific. 

 * A multibyte character may have a state-dependent encoding  ,wherein each sequence of multibyte characters begins in an initial shift state and enters other implementation-defined shift states when specific multibyte characters are encountered in the sequence.  While in the initial shift state, all single-byte characters retain their usual interpretation and do not alter the shift state.  The interpretation for subsequent bytes in the sequence is a function of the current shift state. 

 * A byte with all bits zero shall be interpreted as a null character independent of shift state. 

 * A byte with all bits zero shall not occur in the second or subsequent bytes of a multibyte character. 

   For the source character set, the following shall hold:

 * A comment, string literal, character constant, or header name shall begin and end in the initial shift state. 

 * A comment, string literal, character constant, or header name shall consist of a sequence of valid multibyte characters. 

2.2.2 Character display semantics

   The  active position is that location on a display device where the next character output by the fputc function would appear.  The intent of writing a printable character (as defined by the isprint function) to a display device is to display a graphic representation of that character at the active position and then advance the active position to the next position on the current line.  The direction of printing is locale-specific.  If the active position is at the final position of a line (if there is one), the behavior is unspecified. 

   Alphabetic escape sequences representing nongraphic characters in the execution character set are intended to produce actions on display devices as follows: ( alert ) Produces an audible or visible alert.  The active position shall not be changed.  ( backspace ) Moves the active position to the previous position on the current line.  If the active position is at the initial position of a line, the behavior is unspecified.  ( "form feed" ) Moves the active position to the initial position at the start of the next logical page.  ( "new line" ) Moves the active position to the initial position of the next line.  ( "carriage return" ) Moves the active position to the initial position of the current line.  ( "horizontal tab" ) Moves the active position to the next horizontal tabulation position on the current line.  If the active position is at or past the last defined horizontal tabulation position, the behavior is unspecified.  ( "vertical tab" ) Moves the active position to the initial position of the next vertical tabulation position.  If the active position is at or past the last defined vertical tabulation position, the behavior is unspecified. 

   Each of these escape sequences shall produce a unique implementation-defined value which can be stored in a single char object.  The external representations in a text file need not be identical to the internal representations, and are outside the scope of this Standard. 

Forward references: the fputc function ($4.9.7.3), the isprint function ($4.3.1.7). 

2.2.3 Signals and interrupts

   Functions shall be implemented such that they may be interrupted at any time by a signal, or may be called by a signal handler, or both, with no alteration to earlier, but still active, invocations' control flow (after the interruption), function return values, or objects with automatic storage duration.  All such objects shall be maintained outside the function image (the instructions that comprise the executable representation of a function) on a per-invocation basis. 

   The functions in the standard library are not guaranteed to be reentrant and may modify objects with static storage duration. 

2.2.4 Environmental limits

   Both the translation and execution environments constrain the implementation of language translators and libraries.  The following summarizes the environmental limits on a conforming implementation. 

2.2.4.1 Translation limits

   The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits:/6/

 * 15 nesting levels of compound statements, iteration control structures, and selection control structures

 * 8 nesting levels of conditional inclusion

 * 12 pointer, array, and function declarators (in any combinations) modifying an arithmetic, a structure, a union, or an incomplete type in a declaration

 * 31 declarators nested by parentheses within a full declarator

 * 32 expressions nested by parentheses within a full expression

 * 31 significant initial characters in an internal identifier or a macro name

 * 6 significant initial characters in an external identifier

 * 511 external identifiers in one translation unit

 * 127 identifiers with block scope declared in one block

 * 1024 macro identifiers simultaneously defined in one translation unit

 * 31 parameters in one function definition

 * 31 arguments in one function call

 * 31 parameters in one macro definition

 * 31 arguments in one macro invocation

 * 509 characters in a logical source line

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

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

 * 8 nesting levels for #include d files

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

 * 127 members in a single structure or union

 * 127 enumeration constants in a single enumeration

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

2.2.4.2 Numerical limits

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

"Sizes of integral types <limits.h>"

   The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives.  Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.  

 * maximum number of bits for smallest object that is not a bit-field (byte)

CHAR_BIT                         8

 * minimum value for an object of type signed char

SCHAR_MIN                     -127

 * maximum value for an object of type signed char

SCHAR_MAX                     +127

 * maximum value for an object of type unsigned char

UCHAR_MAX                      255

 * minimum value for an object of type char

CHAR_MIN                     see below

 * maximum value for an object of type char

CHAR_MAX                     see below

 * maximum number of bytes in a multibyte character, for any supported locale

MB_LEN_MAX                       1

 * minimum value for an object of type short int

SHRT_MIN                    -32767

 * maximum value for an object of type short int

SHRT_MAX                    +32767

 * maximum value for an object of type unsigned short int

USHRT_MAX                    65535

 * minimum value for an object of type int

INT_MIN                     -32767

 * maximum value for an object of type int

INT_MAX                     +32767

 * maximum value for an object of type unsigned int

UINT_MAX                     65535

 * minimum value for an object of type long int

LONG_MIN               -2147483647

 * maximum value for an object of type long int

LONG_MAX               +2147483647

 * maximum value for an object of type unsigned long int

ULONG_MAX               4294967295

   If the value of an object of type char sign-extends when used in an expression, the value of CHAR_MIN shall be the same as that of SCHAR_MIN and the value of CHAR_MAX shall be the same as that of SCHAR_MAX .  If the value of an object of type char does not sign-extend when used in an expression, the value of CHAR_MIN shall be 0 and the value of CHAR_MAX shall be the same as that of UCHAR_MAX ./7/

"Characteristics of floating types <float.h>"

   delim $$ The characteristics of floating types are defined in terms of a model that describes a representation of floating-point numbers and values that provide information about an implementation's floating-point arithmetic.  The following parameters are used to define the model for each floating-point type:

   A normalized floating-point number x ($f sub 1$ > 0 if x is defined by the following model:/8/ $x~=~s~times~b sup e~times~sum from k=1 to p~f sub k~times~b sup -k~,~~~e sub min~<=~e~<=~e sub max$

   Of the values in the <float.h> header, FLT_RADIX shall be a constant expression suitable for use in #if preprocessing directives; all other values need not be constant expressions.  All except FLT_RADIX and FLT_ROUNDS have separate names for all three floating-point types.  The floating-point model representation is provided for all values except FLT_ROUNDS . 

   The rounding mode for floating-point addition is characterized by the value of FLT_ROUNDS : -1  indeterminable 0   toward zero 1   to nearest 2   toward positive infinity 3   toward negative infinity All other values for FLT_ROUNDS characterize implementation-defined rounding behavior. 

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

 * radix of exponent representation, b

FLT_RADIX                        2

 * number of base- FLT_RADIX digits in the floating-point mantissa, p

FLT_MANT_DIG

DBL_MANT_DIG

LDBL_MANT_DIG

 * number of decimal digits of precision, $left floor~(p~-~1)~times~{ log sub 10 } b~right floor ~+~ left { lpile { 1 above 0 } ~~ lpile { roman "if " b roman " is a power of 10" above roman otherwise }$

FLT_DIG                          6

DBL_DIG                         10

LDBL_DIG                        10

 * minimum negative integer such that FLT_RADIX raised to that power minus 1 is a normalized floating-point number, $e sub min$

FLT_MIN_EXP

DBL_MIN_EXP

LDBL_MIN_EXP

 * minimum negative integer such that 10 raised to that power is in the range of normalized floating-point numbers,

FLT_MIN_10_EXP                 -37

DBL_MIN_10_EXP                 -37

LDBL_MIN_10_EXP                -37

 * maximum integer such that FLT_RADIX raised to that power minus 1 is a representable finite floating-point number, $e sub max$

FLT_MAX_EXP

DBL_MAX_EXP

LDBL_MAX_EXP

 * maximum integer such that 10 raised to that power is in the range of representable finite floating-point numbers,

FLT_MAX_10_EXP                 +37

DBL_MAX_10_EXP                 +37

LDBL_MAX_10_EXP                +37

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

 * maximum representable finite floating-point number,

FLT_MAX                      1E+37

DBL_MAX                      1E+37

LDBL_MAX                     1E+37

   The values given in the following list shall be replaced by implementation-defined expressions with values that shall be equal to or smaller than those shown. 

 * minimum positive floating-point number x such that 1.0 + x

FLT_EPSILON                   1E-5

DBL_EPSILON                   1E-9

LDBL_EPSILON                  1E-9

 * minimum normalized positive floating-point number, $b sup { e sub min - 1 }$

FLT_MIN                      1E-37

DBL_MIN                      1E-37

LDBL_MIN                     1E-37

Examples

   The following describes an artificial floating-point representation that meets the minimum requirements of the Standard, and the appropriate values in a <float.h> header for type float : $x~=~s~times~16 sup e~times~sum from k=1 to 6~f sub k~times~16 sup -k~,~~~-31~<=~e~<=~+32$

         FLT_RADIX                       16

         FLT_MANT_DIG                     6

         FLT_EPSILON        9.53674316E-07F

         FLT_DIG                          6

         FLT_MIN_EXP                    -31

         FLT_MIN            2.93873588E-39F

         FLT_MIN_10_EXP                 -38

         FLT_MAX_EXP                    +32

         FLT_MAX            3.40282347E+38F

         FLT_MAX_10_EXP                 +38

   The following describes floating-point representations that also meet the requirements for single-precision and double-precision normalized numbers in the IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985),/9/ b and the appropriate values in a <float.h> header for types float and double : $x sub f~=~s~times~2 sup e~times~{ sum from k=1 to 24~f sub k~times~2 sup -k },~~~-125~<=~e~<=~+128$ $x sub d~=~s~times~2 sup e~times~{ sum from k=1 to 53~f sub k~times~2 sup -k },~~~-1021~<=~e~<=~+1024$

         FLT_RADIX                        2

         FLT_MANT_DIG                    24

         FLT_EPSILON        1.19209290E-07F

         FLT_DIG                          6

         FLT_MIN_EXP                   -125

         FLT_MIN            1.17549435E-38F

         FLT_MIN_10_EXP                 -37

         FLT_MAX_EXP                   +128

         FLT_MAX            3.40282347E+38F

         FLT_MAX_10_EXP                 +38

         DBL_MANT_DIG                    53

         DBL_EPSILON 2.2204460492503131E-16

         DBL_DIG                         15

         DBL_MIN_EXP                  -1021

         DBL_MIN    2.2250738585072016E-308

         DBL_MIN_10_EXP                -307

         DBL_MAX_EXP                  +1024

         DBL_MAX    1.7976931348623157E+308

         DBL_MAX_10_EXP                +308

   The values shown above for FLT_EPSILON and DBL_EPSILON are appropriate for the ANSI/IEEE Std 754-1985 default rounding mode (to nearest).  Their values may differ for other rounding modes. 

Forward references: conditional inclusion ($3.8.1).  conditional inclusion ($3.8.1).   


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

 

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