我想知道方法是如何在 C 中實作的。我想知道方法是如何“在幕后”實作的。所以,我做了一個簡單的 C 程式,它有一個類,有 1 個非靜態欄位和 1 個非靜態、非虛擬方法。然后我在主函式中實體化了類并呼叫了方法。我使用了 objdump -d 選項來查看該程式的 CPU 指令。我有一個 x86-64 處理器。這是代碼:
#include<stdio.h>
class TestClass {
public:
int x;
int xPlus2(){
return x 2;
}
};
int main(){
TestClass tc1 = {5};
int variable = tc1.xPlus2();
printf("%d \n", variable);
return 0;
}
以下是方法 xPlus2 的說明:
0000000000402c30 <_ZN9TestClass6xPlus2Ev>:
402c30: 55 push %rbp
402c31: 48 89 e5 mov %rsp,%rbp
402c34: 48 89 4d 10 mov %rcx,0x10(%rbp)
402c38: 48 8b 45 10 mov 0x10(%rbp),%rax
402c3c: 8b 00 mov (%rax),
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/436781.html
標籤:c oop x86 abi member-functions
上一篇:訪問LinkedList中的物件
