问题描述
我必须在现有code碱基以下(工作)code,应用于包括C和C ++之间共享文件,编译于MSVC(2010)和Windows DDK:
I have the following (working) code in an existing code base, used in include file that is shared between C and C++, compiling on MSVC (2010) and Windows DDK:
struct X {
USHORT x;
} typedef X, *PX;
和
enum MY_ENUM {
enum_item_1,
enum_item_2
} typedef MY_ENUM;
据我所知,正确的定义应该是这样的:
As far as I know, correct definition should look like this:
typedef struct {
USHORT x;
} X, *PX;
有什么目的,其具有以下形式?我缺少的东西吗?
Is there any purpose for having the form below? Am I missing something?
推荐答案
事实上,这两个的typedef<&型GT; <&别名GT;
和<&型GT;的typedef<别名方式>
有效期只是来自于语言的语法定义
The fact that both typedef <type> <alias>
and <type> typedef <alias>
are valid simply comes from the language grammar definition.
的typedef
被列为存储类specfifier 的(就像静态
, 汽车
),并且类型本身是被称为的类型说明符的。从标准的6.7节的语法定义,你会发现这些都是免费进行互换:
typedef
is classified as a storage-class specfifier (just like static
, auto
), and the type itself is known as the type-specifier. From the syntax definitions in section 6.7 of the standard, you'll see that these are free to be interchanged:
declaration:
declaration-specifiers init-declarator-list ;
declaration-specifiers:
storage-class-specifier declaration-specifiers
type-specifier declaration-specifiers
type-qualifier declaration-specifiers
function-specifier declaration-specifiers
init-declarator-list:
init-declarator
init-declarator-list , init-declarator
init-declarator:
declarator
declarator = initializer
(注意,当然,这也同样如此结构和非结构的,这意味着双typedef的麻烦;
也是有效的)
这篇关于什么是'结构点¯xtypedef`主场迎战`typedef结构X`的意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!