Naming Array Elements, or Struct And Array Within a Union

前端 未结 4 1848
梦毁少年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:00

    Padding bytes will not cause an issue as all variables are of type double. The compiler will treat Vector4D as a double array. That means, v.Endpoint.z is essentially the same as v[2].

提交回复
热议问题