[ C Frontend / Preprocessor ] Embed Preprocessor Parameter Order

LIU Hao lh_mouse@126.com
Tue Jun 10 08:17:42 GMT 2025


在 2025-6-10 15:52, David Brown via Gcc 写道:
> On 09/06/2025 12:13, Andreas Schwab wrote:
>> On Jun 09 2025, Chris Bazley via Gcc wrote:
>>
>>> C is a language that allows considerable latitude in where things are placed:
>>>
>>>      static int volatile p;
>>>      volatile int static q;
>>
>> C23 says (6.11.5 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.
>>
> 
> ...
> 
> 
> The latitude that C allows for ordering in declarations comes from two main sources.  Sometimes it is 
> because it was thought that it made the syntax and grammar rules of the language simpler.  But mostly it 
> was because the original C standard was formed from existing practice - existing inconsistent C 
> compilers, and existing inconsistent C source code.  It allowed "static int volatile" and "volatile int 
> static" because enforcing an order - /any/ order - would make significant existing C code incorrect with 
> the new standard.  It was not done for good language design - it was done despite it being a bad feature 
> for the language.


May I ask what you would think about this

    ```
    static const struct Foo
      {
        int first;
        int second;
      }
    foo_table[] =
      {
        { 1, 2 },
        { 3, 4 },
        { 5, 6 },
      };
    ```

versus this?

    ```
    struct Foo
      {
        int first;
        int second;
      }
    static const foo_table[] =   // alt. `constexpr foo_table[] =`
      {
        { 1, 2 },
        { 3, 4 },
        { 5, 6 },
      };
    ```




-- 
Best regards,
LIU Hao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20250610/0c3e9ab1/attachment.sig>


More information about the Gcc mailing list