已知結構體成員地址獲取結構體首地址

Eraser的橡皮擦發表於2020-12-24
typedef struct AA_t{
    int first;
    int second;
}AA_t;

AA_t test;
已知test.second的地址為ptr_second;

求test的地址ptr_test;

ptr_test = (AA_t *)(ptr_second -(unsigned long)(&((AA_t*)0)->ptr_second)));

完畢

相關文章