ISO/ IEC JTC1/SC22/WG14 N773

SC22/WG14 N773    J11/97-137


Consistency and clarification changes
Clive D.W. Feather
[email protected]
1997-09-25


Abstract
========
This paper is assembled from those elements of N720, N735, and N739 that
are intended to improve the consistency and clarity of the Standard.
These
changes are intended to ensure that related parts of the Standard are
consistent with one another, or to make the text clearer and harder to
misread. All should be uncontroversial and should not affect any
reasonable program.

Items are given a serial number in this paper, but also carry a note
stating their origin. Items taken from N720 do not have a rationale; the
related DR explains the issues.

Change bars are included where part of a large piece of text is changed,
but not in some items where nearly all the quoted text is changed.
References are relative to Draft 11 pre 3.


Specific items
==============

Item 1
[Was N720 item DR 132]
----------------------
Add to 3.18, as a new paragraph 3:
    The implementation must correctly translate a given program unless
    it can determine that every possible execution of that program would
    result in undefined behaviour.


Item 2
[Was N720 item DR 116]
----------------------
In 6.2.2.1, add to paragraph 3:
    If the array object has register storage class, the behaviour is
    undefined.


Item 3
[Was N720 item DR 109]
----------------------
In 6.3.8 paragraph 5, change:
    ... the result is undefined: ...
to:
    ... the behaviour is undefined: ...


Item 4
[Was N720 item DR 074]
----------------------
Option A
--------
In 6.5.2.1 paragraphs 12 and 14, delete:
    "as necessary to achieve the appropriate alignment"

Option B
--------
In 6.5.2.1 paragraphs 12 and 14, append:
    "or for any other purpose"


Item 5
[Was N720 item DR 157]
----------------------
In 6.5.7, add a new example 5, renumbering the existing one:

    5. Typedefs can be used even where the type name is given a special
    meaning:

        typedef void NO_ARGUMENTS;
        typedef int integer;

        integer main (NO_ARGUMENTS)
        {
            /* ... */
        }

    is a valid definition of the function main in 5.1.2.2.1.


Item 6
[Was N739 item 13]
------------------
Change 6.5.8 paragraph 12 from:

    ... the first member of a union. ...

to:

    ... the first named member of a union. ...

[This isn't strictly necessary, but makes things clearer.]


Item 7
[Was N720 item DR 079]
----------------------
Append to 7.1.2, as a new paragraph 6:
    Any declaration of a library function shall have external linkage.


Item 8
[Was N720 item DR 160]
----------------------
In 7.1.3, paragraph 1, bullet points 2 and 5, change:
    ... reserved for use as identifiers ...
to:
    ... reserved for use as macros and as identifiers ...


Item 9
[Was N735 item 4]
-----------------
The defintions of various symbols in the library are too loose. For
example, on a 16-bit int system, there is nothing to prevent EOF being
defined as -65535, which is, after all, a negative integral constant
expression. However, it might not have a negative value when cast to
int.

More generally, while some symbols have restrictions on them such as
"suitable to be used as the 3rd argument of foo()", and others are never
passed to or returned by functions, there are still some loopholes.

Part A
------
In subclause 7.1.4 paragraph 1, change:

        EDOM
        EILSEQ
        ERANGE

    which expand to integral constant expressions with distinct nonzero
    values, suitable for use in #if preprocessing directives;

to:

        EDOM
        EILSEQ
        ERANGE

    which expand to integral constant expressions with type /int/,
    distinct positive values, and which are suitable for use in #if
    preprocessing directives;

[Note the change from "nonzero" to "positive" to be consistent with the
term "positive error number" later in the paragraph.]

Part B
------
In subclause 7.11 paragraph 3, change:

    ... which expand to positive integral constant expressions with
    distinct values ...

to:

    ... which expand to positive integral constant expressions with type
    /int/ and distinct values ...

Part C
------
In subclause 7.13.1 paragraph 3, change:

        EOF

    which expands to a negative integral constant expression that is
    returned by several functions ...

to:

        EOF

    which expands to an integral constant expression, with type /int/
and
    a negative value, that is returned by several functions ...

Part D
------
In subclause 7.16.1 paragraph 2, change:

        CLOCKS_PER_SEC

    which is the number per second of the value returned by the /clock/
    function.

to:

        CLOCKS_PER_SEC

    which expands to a constant expression with the type /clock_t/
    described below, and which is the number per second of the value
    returned by the /clock/ function.


Item 10
[Was N720 item DR 086]
----------------------
In 7.1.7, modify the words:
    ... additionaly implemented as a macro defined in the header ...
by inserting "function-like" before "macro".


Item 11
[Was N720 item DR 148]
----------------------
In 7.1.8 paragraph 1, change:
    ... so a library function should not be declared explicitly if its
    header is included.
to:
    ... so if a library function is declared explicitly when its header
    is included, one of the techniques shown below should be used to
    ensure the declaration is not affected by such a macro.


Item 12
[Was N735 item 7]
-----------------
There are a couple of places where <ctype.h> is less than clear.

Attach a footnote to subclause 7.3.1.2 (isalpha()), referenced at the
end of the first sentence of paragraph 2:

    ... or isspace is true.[*]  In the "C" locale ...

    [*] The functions islower() and isupper() test true or false
    separately for each of these additional characters; all four
    combinations are possible.

In subclause 7.3.2.1 (tolower()), change the text from:

    Description

    The tolower function converts an uppercase letter to
    the corresponding lowercase letter.

    Returns

    If the argument is a character for which isupper is true and there
    is a corresponding character for which islower is true,
    the tolower function returns the corresponding character;
    otherwise, the argument is returned unchanged.

to:

    Description

    The tolower function converts an uppercase letter to
 |  a corresponding lowercase letter.

    Returns

    If the argument is a character for which isupper is true and there
 |  are one or more corresponding characters for which islower is true,
 |  the tolower function returns one of the corresponding characters
 |  (always the same one for any given locale);
    otherwise, the argument is returned unchanged.

and make the corresponding changes to subclause 7.3.2.2 (toupper()),
7.18.3.1.1 (towlower()) and 7.18.3.1.2 (towupper()).


Item 13
[Was N735 item 13]
------------------
Change the last sentence of subclause 7.11.1.1 (signal()) paragraph 2
from:

    Such a function is called a signal handler.

to:

    An invocation of such a function because of a signal, or of any
    further functions called by that invocation (other than functions
    in the standard library), is called a /signal handler/.

Change subclause 7.11.1.1 paragraph 4 from:

    If the signal occurs other than as the result of calling the abort
    or raise function, the behavior is undefined if the signal handler
    calls any function in the standard library other than the signal
    function itself (with a first argument of the signal number
    corresponding to the signal that caused the invocation of the
    handler) or refers to any object with static storage duration other
    than by assigning a value to an object declared as type volatile
    sig_atomic_t.
    Furthermore, if such a call to the signal function results in a
    SIG_ERR return, the value of errno is indeterminate. [189]

(wording change of DR 149 applied) to:

    If the signal occurs other than as the result of calling the abort
    or raise function, the behaviour is undefined if the signal handler
 |  includes a call to any function in the standard library other than:
 |  - the abort, exit, or longjmp functions, or
 |  - the signal function itself, with the first argument equal to the
 |    signal number corresponding to the signal that caused the
 |    invocation of the handler,
 |  or refers to any object with static storage duration other than
 |  - by assigning a value to an object declared as volatile
sig_atomic_t,
 |  - as part of the first argument to a call to the longjmp
 |    function[*], or
 |  - as part of the execution of the abort, exit, or longjmp functions
 |    (but not as part of any signal handler or function registered with
 |    the atexit function called from them).
    Furthermore, if such a call to the signal function results in a
    SIG_ERR return, the value of errno is indeterminate. [189]

 |  [*] That is, given:
 |          static jmp_buf env;
 |  then:
 |          longjmp (env, 0);
 |  is valid, but:
 |          auto jmp_buf e2;
 |          memcpy (e2, env, sizeof env);
 |          longjmp (e2, 0);
 |  even though the value of /env/ will eventually be used in such a
 |  call.

In subclause 7.11.1.1 paragraph 7, change:
    ... for the most recent call to /signal/ for ...
to:
    ... for the most recent successful call to /signal/ for ...


Item 14
[Was N735 item 3]
-----------------
Add to the end of 7.12 paragraph 3:

    It is permitted to create a pointer to a va_list and pass that
    pointer to another function, in which case the original function
    may make further use of the original list after the other function
    returns.


Item 15
[Was N720 item DR 137]
----------------------
In 7.13.6.1 and 7.19.2.1, change footnotes 201 and 254 to:
    [201/254] The results of all floating conversions of a negative
zero,
    and of negative values that round to zero, include a minus sign.


Item 16
[Was N720 item DR 151]
----------------------
In 7.13.6.1 and 7.19.2.1, '#' flag, change:
    ... the first digit of the result to be a zero.
to:
    ... the first digit of the result to be a zero (if the value and
    precision are both 0, a single 0 is printed).


Item 17
[Was N720 item DR 167]
----------------------
In 7.13.6.1 and 7.19.2.1, 'n' specifier, change the last sentence to:
    No argument is converted, but one is consumed. If the conversion
    specification with this conversion specifier is not one of %n, %ln,
    %lln, or %hn, the behaviour is undefined.

In 7.13.6.2, 'n' specifier, add %lln to the list.

In J.2, add:
    A %n conversion specification for the fprintf or fscanf functions is
    not one of %n, %ln, %lln, or %hn. (7.13.6.1, 7.13.6.2, 7.19.2.1,
    7.19.2.2).


Item 18
[Was N735 item 18a]
-------------------
Change the last sentence of subclause 7.14.3 paragraph 1 from:

    The value of a pointer that refers to freed space is indeterminate.

to:

 |  The value of a pointer that refers to freed space, or to space that
 |  has subsequently been moved, is indeterminate.

In subclause 7.14.3.4 (realloc ()) paragraph 2, change:

    or if the space has been deallocated by a call to the /free/ or
    /realloc/ function,

to:

 |  or if the space has been deallocated or moved by a call to the
 |  /free/ or /realloc/ function,


Item 19
[Was N720 item DR 161]
----------------------
In 7.20, change each instance of:
    (followed by any combination of digits, letters, and underscore)
to:
    (possibly followed by any combination of digits, letters, and
    underscore)


Item 20
[Was N720 item DR 133]
----------------------
Add the list of items in the DR to subclause J.2.


Item 21
[Was N720 item DR 168]
----------------------
In J.2 referring to 6.3, add "a type compatible with" in the places that
TC1 changed 6.3 itself.

==== ENDS ====