基本的なCDB:CDBはスコープに注目する方法を異なりますか?

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

  •  15-11-2019
  •  | 
  •  

質問

コンパイルした場合:

int *a;

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

そしてCDBでメインを分解します:

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    
.

so * aはポインタプロジェクトで象徴されています!a。すべて良い。

しかし、メイン内のポインタを宣言した場合:

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

Aがスタックポインタからのオフセットであることがわかります(私は信じています)、だから私が期待する人間が読める構造(PointersProject!Main!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のデバッグを見ながら音楽に触発されました: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