Re: [PATCH v2 2/2] Remove trailing semicolon after RB_GENERATE_STATIC

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 



On 2021-06-04, David Newall <openssh@xxxxxxxxxxxxxxx> wrote:
> On Thu, 13 May 2021, Michael Forney wrote:
>> This expands to a series of function definitions, so the semicolon is
>> not necessary (in fact, it is not allowed in ISO C).
>
> I went looking for that, and failed to find it.  The best I could find
> says otherwise.  ISO/IEC 9899:2017 (C17): Section 6.8.3 Expression and
> null statements specifically allows a null statement (as you'd expect
> given the section name).
>
> It must be a new revision.  When did the null statement become
> disallowed?  Reference, please.

I'm not sure why statements are being discussed here. The patch is
about top-level external definitions (declarations and function
definitions), not statements. As you point out, null statements are
perfectly valid. Null declarations are not.

The relevant sections of the C standard are external definitions
(https://port70.net/~nsz/c/c99/n1256.html#6.9) and declarations
(https://port70.net/~nsz/c/c99/n1256.html#6.7).

I'll reproduce these parts of the grammar:

          translation-unit:
                  external-declaration
                  translation-unit external-declaration
          external-declaration:
                 function-definition
                 declaration

          function-definition:
                 declaration-specifiers declarator declaration-listopt
compound-statement
          compound-statement:
                { block-item-listopt }

          declaration:
                 declaration-specifiers init-declarator-listopt ;
          declaration-specifiers:
                 storage-class-specifier declaration-specifiersopt
                 type-specifier declaration-specifiersopt
                 type-qualifier declaration-specifiersopt
                 function-specifier declaration-specifiersopt

As you can see, a function definition ends with a '}', not an optional
semicolon. Additionally, there is no "null declaration",
declaration-specifiers are a  required part of a declaration. This has
always been the case, from C89 to the latest C23 draft.

If you enable -Wpedantic, gcc will flag these null declarations:

$ echo ';' | gcc -Wpedantic -c -x c -
<stdin>:1:1: warning: ISO C does not allow extra ';' outside of a
function [-Wpedantic]

> If the null statements are still allowed, I urge that the patch be
> reverted as it would then be mere noise in the change history, a
> distraction at best, and a source of errors at worst.
>
> The benefit of the semi-colon (if allowed) is that it makes explicit
> that the macro is a psuedo-statement. Also, if the macro is redefined
> to produce an expression that is not a (terminated) statement, the
> program will no longer compile.

If the macro is redefined to produce an expression or statement, it
won't compile because statements and expressions aren't allowed at
top-level, only in function bodies. The best you could do if you
wanted to add a semicolon after a macro that expands to a function
definition would be to require C11 and use a dummy `_Static_assert(1,
"")` at the end.

If you care deeply about extending C with null declarations, I suggest
you send a proposal to WG14.
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev



[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux