C99 可以类型修饰符出现在类型的右边
C99 can type modifiers appear to the right of the type
我喜欢将类型限定符放在类型的右侧,尤其是对于指针声明,因为这样可以更轻松地阅读使用 right-left rule 的声明。
例如
uint8_t volatile * const p_foo; // p_foo is a const pointer to a volatile uint8_t
将类型限定符放在类型的右侧在 C99 中是合法的。但是像 signed
和 long
这样的类型修饰符呢?
例如
`int signed const * const p_bar; // is it legal in C99 to put 'signed' to the right of 'int'?`
FWIW gcc -std=c99 -pedantic-errors
对此没有发出任何声音。
第 6.7.2 节第 2 段 ISO/IEC 9899:TC3
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name.Each list of type specifiers shall be one of the following sets (delimited by commas, when there is more than one set on a line); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
由于int
、char
等本身就是说明符,那么我认为答案是“是的,将signed int
的顺序颠倒为[=13=是合法的” ]".
我喜欢将类型限定符放在类型的右侧,尤其是对于指针声明,因为这样可以更轻松地阅读使用 right-left rule 的声明。 例如
uint8_t volatile * const p_foo; // p_foo is a const pointer to a volatile uint8_t
将类型限定符放在类型的右侧在 C99 中是合法的。但是像 signed
和 long
这样的类型修饰符呢?
例如
`int signed const * const p_bar; // is it legal in C99 to put 'signed' to the right of 'int'?`
FWIW gcc -std=c99 -pedantic-errors
对此没有发出任何声音。
第 6.7.2 节第 2 段 ISO/IEC 9899:TC3
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name.Each list of type specifiers shall be one of the following sets (delimited by commas, when there is more than one set on a line); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
由于int
、char
等本身就是说明符,那么我认为答案是“是的,将signed int
的顺序颠倒为[=13=是合法的” ]".