Casting one C structure into another

前端 未结 8 672
再見小時候
再見小時候 2020-11-27 03:30

I have two identical (but differently named) C structures:

typedef struct {
      double x;
      double y;
      double z;
} CMAcceleration;


typedef struc         


        
8条回答
  •  [愿得一人]
    2020-11-27 03:50

    Another version of the utility function making use of C99:

    static inline struct Vector3d AccelerationToVector(struct CMAcceleration In)
    {
        return (struct Vector3d){In.x, In.y, In.z};
    }
    

    With the compiler optimization turned up (e.g., -Os), this should turn into absolutely no object code when invoked.

提交回复
热议问题