【发布时间】:2020-07-09 17:05:23
【问题描述】:
这两者有区别吗?
typedef struct {
unsigned int day;
unsigned int month;
unsigned int year;
}birthday_t;
typedef struct {
const birthday_t birthday;
const unsigned int id;
}person_t;
person_t person = {
.birthday = {1,20,2000},
.id = 123};
和
typedef struct {
unsigned int day;
unsigned int month;
unsigned int year;
}birthday_t;
typedef struct {
birthday_t birthday;
unsigned int id;
}person_t;
const person_t person = {
.birthday = {1,20,2000},
.id = 123};
如果结构中的成员是 const 但结构不是常量(上),这与没有 const 成员的 const 结构不同(下)吗?
【问题讨论】:
-
您能解释一下这是为什么吗?
-
由于您专门标记了 C99,您可能只询问 C,而不询问 C++?
-
C 还是 C++?选择一种语言。
-
我知道初始化成员时 C++ 的语法是不同的。但是,在示例中处理 const 的方式之间是否存在根本区别? C首选
-
.birthday = {1,20,2000},从什么时候开始第 20 个月存在?