• Re: "A diagram of C23 basic types"

    From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Mon Feb 2 09:34:26 2026
    From Newsgroup: comp.lang.c

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]

    Trailing commas in argument lists and/or parameter lists
    could be accepted as an extension, even without giving a
    diagnostic as I read the C standard, but implementations
    are certainly within their rights to reject them.

    I believe a diagnotic is required.

    C17 5.1.1.3:

    A conforming implementation shall produce at least one
    diagnostic message (identified in an implementation-defined
    manner) if a preprocessing translation unit or translation
    unit contains a violation of any syntax rule or constraint,
    even if the behavior is also explicitly specified as undefined
    or implementation-defined.

    A trailing comma on an argument or parameter list is a violation
    of a syntax rule.

    I believe a diagnostic is not required, because the C standard
    explicitly allows extensions. If such diagnostics were required
    even for constructions that are part of extensions, then there is no
    reason to allow extensions, because whatever behavior is desired
    could be done anyway, under the freedom granted by undefined
    behavior. It would be stupid to explicitly grant permission to do
    something if it could be done anyway without the permission. And
    the people who wrote the C standard are not stupid.

    I believe that the fact that a conforming implementation provides an extension does not relieve it of its responsibility to diagnose syntax
    errors and constraint violations.

    The authors of both gcc and clang appear to agree. A concrete example:
    gcc has an extension (which clang also provides) allowing the middle
    operand of a conditional operator to be omitted, so that `x ? : y` is equivalent to `x ? x : y`, except that x is evaluated only once.

    By default, use of this extension (which would be a syntax
    error if the extension did not exist) is not diagnosed; neither
    compiler is conforming by default. With "-std=c17 -pedantic" or
    "-std=c17 -pedantic-errors", both issue a warning or error message, respectively.

    Your logic is bad. First the diagnostics are produced only because
    you have asked them to be produced by giving the -pedantic option.
    Second there are other cases where diagnostics are not given even
    with -pedantic. Third the statement that without -pedantic the
    compilers are not conforming does not mean that their behavior in
    any particular case is not conforming; the argument implicitly uses
    circular logic, using the non-issuance of a diagnostic to imply that
    the compilers are not conforming, but whether a conforming
    implmentation must issue a diagnostic is the question being
    considered.

    It doesn't make sense for the C standard to include a statement that
    extensions are allowed if they would be allowed anyway.
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.lang.c on Mon Feb 2 16:15:33 2026
    From Newsgroup: comp.lang.c

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]
    Trailing commas in argument lists and/or parameter lists
    could be accepted as an extension, even without giving a
    diagnostic as I read the C standard, but implementations
    are certainly within their rights to reject them.

    I believe a diagnotic is required.

    C17 5.1.1.3:

    A conforming implementation shall produce at least one
    diagnostic message (identified in an implementation-defined
    manner) if a preprocessing translation unit or translation
    unit contains a violation of any syntax rule or constraint,
    even if the behavior is also explicitly specified as undefined
    or implementation-defined.

    A trailing comma on an argument or parameter list is a violation
    of a syntax rule.

    I believe a diagnostic is not required, because the C standard
    explicitly allows extensions. If such diagnostics were required
    even for constructions that are part of extensions, then there is no
    reason to allow extensions, because whatever behavior is desired
    could be done anyway, under the freedom granted by undefined
    behavior. It would be stupid to explicitly grant permission to do
    something if it could be done anyway without the permission. And
    the people who wrote the C standard are not stupid.

    I believe that the fact that a conforming implementation provides an
    extension does not relieve it of its responsibility to diagnose syntax
    errors and constraint violations.

    The authors of both gcc and clang appear to agree. A concrete example:
    gcc has an extension (which clang also provides) allowing the middle
    operand of a conditional operator to be omitted, so that `x ? : y` is
    equivalent to `x ? x : y`, except that x is evaluated only once.

    By default, use of this extension (which would be a syntax
    error if the extension did not exist) is not diagnosed; neither
    compiler is conforming by default. With "-std=c17 -pedantic" or
    "-std=c17 -pedantic-errors", both issue a warning or error message,
    respectively.

    Your logic is bad. First the diagnostics are produced only because
    you have asked them to be produced by giving the -pedantic option.
    Second there are other cases where diagnostics are not given even
    with -pedantic. Third the statement that without -pedantic the
    compilers are not conforming does not mean that their behavior in
    any particular case is not conforming; the argument implicitly uses
    circular logic, using the non-issuance of a diagnostic to imply that
    the compilers are not conforming, but whether a conforming
    implmentation must issue a diagnostic is the question being
    considered.

    It doesn't make sense for the C standard to include a statement that extensions are allowed if they would be allowed anyway.

    I see no circular logic.

    A concrete example:

    int main(void) {
    return 0 ? : 0;
    }

    This relies on an extension implemented by gcc and clang.
    It violates a syntax rule. (This is proposed as a new feature in
    C 202y; see <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3804.txt>.)

    N3220 5.1.1.3 requires a diagnostic for any translation unit
    containing a violation of any syntax rule or constraint. It does
    not state an exception to this rule for extensions. That is the
    basis on which I conclude that a diagnostic is required.

    The diagnostics are produced because I used a conforming C compiler,
    and a conforming C compiler must produce a diagnostic for that
    translation unit. (It happens that a way to do that is to use
    "gcc -std=c17 -pedantic", or "-std=c23 -pedantic" if you have a
    new enough version of gcc.)

    Furthermore, my intent was not to use the behavior of gcc to prove
    that my argument is correct. It was only to demonstrate that
    the authors of gcc (and clang) apparently agree that a diagnostic
    is required. I have disagreed with the gcc and clang authors at
    times, but in this case I believe they are correct.

    I would like the standard to be more explicit on this point.
    I would like to see a future edition of the standard explicitly state
    that extensions do not affect the requirement for a diagnostic for
    violations of syntax rules and constraints. Or, alternatively, a
    future edition could state that such a diagnostic is *not* required
    (which would in my opinion be a change from C23.)

    I'm sympathetic to the idea that use of an extension should not
    trigger a mandatory diagnostic, but 5.1.1.3 is explicit and does
    not seem to allow that.

    I've kept all the context, since you've posted your followup nearly
    10 months after my previous article. In the future, I may or
    may not ignore any followups that are delayed by more than, say,
    a month. A request: If you post a followup after a long delay,
    please acknowledge that in the post.
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21b-Linux NewsLink 1.2