【代码】

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
/*
version: 1.0
author: hellogiser
blog: http://www.cnblogs.com/hellogiser
date: 2014/9/25
*/


#include "stdafx.h"
#include <iostream>
using namespace std;

#define OFFSET(s,m) ((int)(&(((s*)0)->m)))
struct MyStruct
{
    
int a;
    
int b;
    
int c;
};

void test_offset()
{
    cout << OFFSET(MyStruct, a) << endl; 
// 0
    cout << OFFSET(MyStruct, b) << endl; // 4
    cout << OFFSET(MyStruct, c) << endl; // 8
}

int main()
{
    test_offset();
    
return 0;
}

相关文章:

  • 2021-09-20
  • 2021-09-02
  • 2022-12-23
  • 2020-12-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
猜你喜欢
  • 2022-12-23
  • 2021-08-27
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
相关资源
相似解决方案