기본 CDB : CDB는 해당 범위를 표시하는 방법을 어떻게 변합니다.

StackOverflow https://stackoverflow.com/questions/6048602

  •  15-11-2019
  •  | 
  •  

문제

i 컴파일 :

int *a;

void main(void)
{
    *a = 1;
}
.

그리고 CDB에서 메인을 분해하십시오. INK :

pointersproject!main:
00000001`3fd51010 mov     rax,qword ptr [pointersproject!a (00000001`3fd632f0)]
00000001`3fd51017 mov     dword ptr [rax],1
00000001`3fd5101d xor     eax,eax
00000001`3fd5101f ret    
.

그래서 * a는 pointersproject에 의해 상징됩니다! a.모두 좋은.

그러나 메인 내의 포인터를 선언하는 경우 :

void main(void)
{
    int *a;
    a = 1;
}
.

나는 A가 스택 포인터 (나는 믿음)의 오프셋 일뿐 만 아니라 인간이 읽을 수있는 구조가 될 것입니다.

pointersproject!main:
00000001`3fd51010 sub     rsp,18h
00000001`3fd51014 mov     rax,qword ptr [rsp]
00000001`3fd51018 mov     dword ptr [rax],1
00000001`3fd5101e xor     eax,eax
00000001`3fd51020 add     rsp,18h
00000001`3fd51024 ret
.

이것은 컴파일러가 다른 것으로 수행 한 것에 대한 나의 이해에 대해서는 아마도 다음과 같습니다. 왜냐하면 누구든지 내가 기대하는 것에 대한 표기법이 아닌 이유를 설명 할 수 있습니까?

(X64 Windows 디버깅을 보는 동안 Musing에서 영감을 얻은 : Dmitry Vostokov의 실제 재단)

도움이 되었습니까?

해결책

When a variable is defined inside a function, it is an automatic variable unless explicitly declared static. Such variables only live during the execution of the function and are normally allocated in the stack, thus they are deallocated when the function exits. The change you see in the complied code is not due to the change in scope but to the change from static to automatic variable. If you make a static, it will not be allocated in the stack, even if its scope is the function main.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top