看板 C_and_CPP 關於我們 聯絡資訊
有了 cfront 之後, 可以看到 member function pointer 是怎麼實作的。 void (A::*mf)() = 0; printf("sizeof(mf): %u\n", sizeof(mf)); 這個程式碼被轉成 typedef int (*__vptp)(void); struct __mptr {short d; short i; __vptp f; }; struct __mptr __1mf ; printf ( (const char *)"sizeof(mf): %u\n", sizeof __1mf ) ; 所以這就是為什麼這個指標印出來的大小是 16 (64bit 機器), 而不是 8。 cfront 可以為我們揭露大多數 c++ 實作的祕密。 -- 紙上得來終覺淺,絕知此事要躬行。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.218.53.138 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1527848357.A.F1E.html ※ 編輯: descent (61.218.53.138), 06/01/2018 18:19:34
bigbite: 推 06/02 13:13