小编Car*_*son的帖子

Typedef 在本地共享对象别名,但不是全局共享,但是如果与 typedef 不是同义,则 at tag 可以在本地或全局共享它,为什么?

这是问题的概述(clang 抛出的错误代码):

标签的 typedef 和 struct def;

typedef struct tag {int tag;} tag;
Run Code Online (Sandbox Code Playgroud)

这工作得很好:

struct tag {int tag;} tag;
Run Code Online (Sandbox Code Playgroud)

而这些 typedef 错误之一:

typedef struct {int tag;} tag;

/*or*/

typedef struct tag {int tag;} tag;

/*and then this following code fails from either of the two 
previous typedefs which the compiler errors about as being 
redeclared as as different kind of symbol. Not allowed to share 
typedef with object id:*/

tag tag;
Run Code Online (Sandbox Code Playgroud)

当指定相同名称的 typedef/tag 时,两个全局变量上的编译器错误:

/*error: redefinition of 'tag' as different …
Run Code Online (Sandbox Code Playgroud)

c struct pointers scope typedef

-1
推荐指数
1
解决办法
141
查看次数

标签 统计

c ×1

pointers ×1

scope ×1

struct ×1

typedef ×1