Search code examples
c++classgccattributespacked

Using attribute packed for classes in GCC


GCC doc says:

You may only specify the packed attribute attribute on the definition of an enum, struct or union, not on a typedef that does not also define the enumerated type, structure or union.

Does it mean that I cannot apply this attribute for classes?


Solution

  • The documentation for GCC 9.x was updated to include "class" in that list:

    You may only specify the packed attribute on the definition of an enum, struct, union, or class, not on a typedef that does not also define the enumerated type, structure, union, or class.

    So you can certainly apply that attribute to classes, at least as of GCC 9.x, but probably also in earlier versions.