offsetof

核心

结构体在C和C++中的定义不同!!!

定义

C

  1. # 方式一
  2. typedef struct xxx_s{
  3. ···
  4. }xxx_t;
  5. # 方式二(👍)
  6. typedef struct xxx_s xxx_t;
  7. struct xxx_s{
  8. ···
  9. };

C++

  1. struct Xxx {
  2. ···
  3. };

与类Class一致,仅访问控制不同:结构体默认public,类默认private