是否有C++11/14替代__attribute__((已打包))

Is there a C++11/14 alternative to __attribute__((packed))

本文关键字:attribute 是否 C++11 替代      更新时间:2023-10-16

C++11引入了标准化属性语法的概念。我找不到所有支持的属性的列表。是否存在__attribute__((packed))的C++11属性替代方案?

例如

struct __attribute__((packed)) Pack {
   uint8_t field1;
   uint8_t field2;
};

不幸的是,没有。标准目前定义的属性是:

  • [[noreturn]]
  • [[carries_dependency]]
  • [[deprecated]]/[[deprecated(reason)]]

其他一切都是由实现定义的。