Is “typedef” in between the type and the alias standard-conformant?

前端 未结 5 537
春和景丽
春和景丽 2021-02-06 20:59

I stumbled upon some code where the typedef keyword is in between the type and the alias name like in

int typedef INT;

It compiles

5条回答
  •  梦如初夏
    2021-02-06 21:45

    The typedef keyword is classified as a storage class specifier in C, though the standard explicitly remarks that that's for convenience in expressing the formal language syntax. It nevertheless follows that typedef can appear in exactly the same places that any other storage class specifier, such as extern or static, can appear. [C2011, 6.7.1/5]

    In fact, the syntax allows storage-class specifiers to be intermixed with type specifiers, type qualifiers, and other "declaration specifiers" in declarations. [C2011, 6.7/1, 6.7/6]

    Thus, yes, it is valid to put the typedef keyword after the type name, as in your example.

提交回复
热议问题