Casting double array to a struct of doubles

前端 未结 6 1749
醉梦人生
醉梦人生 2020-11-30 14:54

Is it OK to cast a double array to a struct made of doubles?

struct A
{
   double x;
   double y;
   double z;
};

int main (int argc , char ** argv)
{
   do         


        
6条回答
  •  温柔的废话
    2020-11-30 15:32

    From all I know the answer is: yes.

    The only thing that could throw you off is a #pragma directive with some very unusual alignment setting for the struct. If for example a double takes 8 bytes on your machine and the #pragma directive tells to align every member on 16-byte boundaries that could cause problems. Other than that you are fine.

提交回复
热议问题