结构后的公共是什么意思
What does : public after struct mean?
struct hpet : public description_table_header
{
uint8_t hardware_rev_id;
uint8_t comparator_count:5;
uint8_t counter_size:1;
uint8_t reserved:1;
uint8_t legacy_replacement:1;
pci_vendor_t pci_vendor_id;
address_structure address;
uint8_t hpet_number;
uint16_t minimum_tick;
uint8_t page_protection;
} __attribute__((packed));
为什么结构体名称后面有公共__attribute__((packed))
,为什么被打包在偏执狂中???这是 HPET(高精度事件计时器)的表。
代码是C++的,而不是你标记的 C。这是一个非常重要的细节。
此处public
是继承的访问说明符(结构继承自 description_table_header
)。这将在所有好的C++教科书中涵盖。关于SO的一个相关问题是:私有、公共和受保护继承之间的区别。实际上不需要struct
的public
规范,因为对于结构来说,这是默认值。
__attribute__((packed))
是特定于编译器的扩展,用于指定struct
的布局。在这种情况下,struct
被打包,以便结构中没有填充。
在C++中,冒号:
后跟可选的 public
/private
/protected
指示符,类型名称是指定继承的语法。
在代码中,hpet
类继承description_table_header
类。
有关公共、私有和受保护继承之间差异的讨论,请参阅此答案。
相关文章:
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 线应该是什么意思
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 表达式"b=(b-x)&x"是什么意思?
- 这个表达是什么意思?
- 此代码验证公式是什么意思?
- 跟踪日志中的T.11803()是什么意思?
- 这个额外的关键字在这个 c++ 类声明中是什么意思?
- * 和 ** 在 C++ 函数声明中是什么意思?
- _T("xyz")是什么意思?
- #define Dbg(fmt,..) (0) 是什么意思? 警告:表达式无效
- 这行代码到底是什么意思?
- 在命名空间名称之前加上 :: 是什么意思?
- 从字符数组的元素中减去'a'是什么意思
- "friend"关键字在C++中是什么意思?
- 减法中的"0"是什么意思?
- 字符数组前面的加号是什么意思?
- 这里的字符串函数是什么意思