gcc - Where does constant local variable array go in memory for a 'C' program -
gcc - Where does constant local variable array go in memory for a 'C' program -
i using gcc 4.8.1 , doesn't seem store const variable local main in info segment. below code , memory map 3 such programs:
code 1:
int main(void) { //char a[10]="hello"; //1 //const char a[10] = "hello"; //2 homecoming 0; } memory map above: text info bss dec hex filename 7264 1688 1040 9992 2708 a.exe
code 2:
int main(void) { char a[10]="hello"; //const char a[10] = "hello"; homecoming 0; } memory map 2: text info bss dec hex filename 7280 1688 1040 10008 2718 a.exe
code 3:
int main(void) { //char a[10]="hello"; const char a[10] = "hello"; homecoming 0; } memory map 3 : text info bss dec hex filename 7280 1688 1040 10008 2718 a.exe
i not see difference in info segment between 3 codes. can please explain result me.
thanks in anticipation!
this should happen:
code 1: nil stored anywhere.
code 2: a
stored on stack. not stored in .data
.
code 3 a
either stored on stack or in .rodata
, depending on whether initialized constant look or not. optimizer might decide store in .text
(together code).
i not see difference in info segment between 3 codes.
that's because there should no difference. .data
used non-constant variables static storage duration initialized value other zero.
c gcc memory
Comments
Post a Comment