C pointers vs direct member access for structs

前端 未结 9 2672
抹茶落季
抹茶落季 2020-12-16 17:59

Say I have a struct like the following ...

typedef struct {
  int WheelCount;
  double MaxSpeed;
} Vehicle;

... and I have a global variabl

9条回答
  •  失恋的感觉
    2020-12-16 18:06

    In general, accessing the struct directly would be quicker, as it won't require an extra pointer dereference. The pointer dereference means that it has to take the pointer (the thing in the variable), load whatever it points to, then operate on it.

提交回复
热议问题