結構體
typedef struct {
char a;char b;
int abc;
}stTest;
代碼如下:
int m = offsetof(stTest, abc);
stTest test ;
*(int*)(((char*)(&test))+m) = 1231424;
剛開始我犯了一個錯誤,錯誤的寫法如下:
*(int*)(((&test))+m) = 1231424;
必須要將(&test)轉爲char* 再加上成員變量偏移量,才能正確通過地址找到變量位置。
*(int*)(((char*)(&test))+m) = 1231424;
這樣纔對