【问题标题】:What is the difference when defining structs with typedef?用 typedef 定义结构有什么区别?
【发布时间】:2021-04-01 23:02:43
【问题描述】:

选项 1:

typedef struct s{
                 int x;
                 double y;
                 char z;
                 }mystruct;

选项 2:

typedef struct {
                int x;
                double y;
                char z;
                }mystruct;

这两个选项有什么区别?

【问题讨论】:

  • this 有帮助吗?
  • @costaparas 我找不到我所要求的具体细微差别的答案,但我找到了另一个有用的信息
  • 选项 2 将 mystruct 定义为匿名结构。选项 1 将 mystruct 定义为 struct s

标签: c struct typedef


【解决方案1】:

使用选项 1,您可以像这样声明一个变量:

struct s foo;

mystruct foo;

使用选项 2 唯一的可能性是:

mystruct foo;

【讨论】:

    猜你喜欢
    • 2010-11-13
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    相关资源
    最近更新 更多