用宏定義FIND求一個結構體裏某個變量相對於sturct的偏移量
如:struct student
{
int a;
char b[20];
double ccc;
}
則:FIND(student,a)//等於0
FIND(student,b)//等於4
#define FIND(sturct,e) (size_t)&(((struct*)0)->e)
因爲該結構體首地址就是爲0,所以其實就是得到成員e的偏移量
{
int a;
char b[20];
double ccc;
}
則:FIND(student,a)//等於0
FIND(student,b)//等於4
#define FIND(sturct,e) (size_t)&(((struct*)0)->e)
因爲該結構體首地址就是爲0,所以其實就是得到成員e的偏移量
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
第一行第一列遞增,其餘等於上面的數字和左邊的數字的和
f(m,n) = {n (m=1)m (n=1)f(m-1,n)+f(m,n-1) (上面一行和左邊一行之和) } 遞歸方法: #include <
C__Monkey
2020-07-02 09:37:50
編寫函數,要求輸入年月日時分秒,輸出該時間的下一秒
#include <iostream> #include <string> using namespace std; void ResetTheTi
C__Monkey
2020-07-02 09:37:50
找出水仙花數
#include <iostream> #include <cmath> using namespace std; int main() {int
C__Monkey
2020-07-02 09:37:50
查找A數組中某值與B中某值等值
#include <iostream> using namespace std; void matching(int a[],int b[],int
C__Monkey
2020-07-02 09:37:48
C++去掉註釋
#include <string.h> #include <stdlib.h> #include <stdio.h> #include <fcntl
C__Monkey
2020-07-02 09:37:48
一個五位數ABCDE乘與4爲EDCBA五個數還不重複
#include <iostream> using namespace std; int main() {for (int i=10000; i<1
C__Monkey
2020-07-02 09:37:48
c/c++常見面試題02
ult_lolicon
2020-07-01 17:43:53
c/c++常見面試題01
ult_lolicon
2020-07-01 17:43:43
c/c++常見面試題03
ult_lolicon
2020-07-01 17:43:43
c/c++常見面試題05
ult_lolicon
2020-07-01 17:43:43
多態內容:虛函數、純虛函數、抽象類、虛析構函數、虛擬繼承
不会code的菜鸟
2020-06-16 11:37:13
sizeof與strlen有哪些區別
不会code的菜鸟
2020-06-16 11:37:13
C++中const有什麼作用
不会code的菜鸟
2020-06-16 11:37:13