Naming Array Elements, or Struct And Array Within a Union

前端 未结 4 1849
梦毁少年i
梦毁少年i 2021-01-17 13:50

Consider the following struct:

struct Vector4D
{
   union
   {
      double components[4];
      struct { double x, y, z, t; } Endpoint;
   };
};
         


        
4条回答
  •  误落风尘
    2021-01-17 14:22

    1. yes
    2. depends on the alignment needs of the architecture and the compilers strategy
    3. no, but you could make a object wrapper (but you will end up with .z() instead of just .z)

    Most compilers should support squashing a structure using a pragma or an attribute. #pragma pack for example.

提交回复
热议问题