Printf the current address in C program

后端 未结 8 1333
时光说笑
时光说笑 2021-02-04 12:27

Imagine I have the following simple C program:

int main() {

int a=5, b= 6, c;
c = a +b; 
return 0;
}

Now, I would like to know the address of

8条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 12:44

    Tested in Visual Studio 2008:

    int addr;
    __asm
    {
        call _here
        _here: pop eax
        ; eax now holds the PC.
        mov [addr], eax
    }
    
    printf("%x\n", addr);
    

    Credit to this question.

提交回复
热议问题