2016-11-08 69 views
0
const int hello= 0x1111; 
int main(){ 
} 

我建立一個非常簡單的代碼時發現全局常量變量的值,並與在C,編譯

gcc t.c -g -o t.out 

我可以使用objdump的或納米或任何工具以確保常數變量值編譯? 我總是覺得可變的 「你好」 的地址,卻找不到值

任何人都可以幫助我,非常感謝

+0

我不明白你在問什麼。 –

+0

顯示輸出 –

回答

1

的示例代碼

const int hello = 0xdeadbeef; 
int main() 
{ 
    return 0; 
} 

編譯

gcc-4.9 -W -Wall -Wextra -pedantic -std=c11 fortests.c -o fortests 

轉儲內容

objdump -xDSs fortests | less 

(甩有點過分,但不用花一分錢,所以......咩......)和搜索hello

0000000000400594 g  O .rodata  0000000000000004    hello 

這意味着它是在部分.rodata。我們明確要求objdump列出所有部分的內容,所以我們在這裏列出了值0xdeadbeef

Contents of section .rodata: 
    400590 01000200 efbeadde     ........ 
        ^^^^^^^^ 
      here |||||||| 

而現在應該清楚,爲什麼你很難找到它。