Python Front-end to GCC

Albert van der Horst albert at spenarnc.xs4all.nl
Fri Nov 1 23:48:05 CET 2013


In article <mailman.1362.1382460759.18130.python-list at python.org>,
Chris Kaynor  <ckaynor at zindagigames.com> wrote:
>-=-=-=-=-=-
<SNIP>
>Global:
>
>int arr[10];
>int main()
>{
>  int i;
>  for (i = 0; i < 10; i++) {
>    printf("arr[%d] = %d\n", i, arr[i]);
>    }
>    printf("\n");
>    return 0;
>}
>
>As for a reference:
>http://stackoverflow.com/questions/1831290/static-variable-initialization
> and
>http://stackoverflow.com/questions/3373108/why-are-static-variables-auto-initialized-to-zero,
>both of which then reference the C++ standard.


Or even better:

#include<stdio.h>

int arr[] = {1,2,3,4,5,6,7,8};

int main()
{
  int i;
  for (i = 0; i < sizeof(arr)/sizeof(int); i++) {
    printf("arr[%d] = %d\n", i, arr[i]);
    }
    printf("\n");
    return 0;
}

Output:
"
albert at cherry:/tmp$ a.out
arr[0] = 1
arr[1] = 2
arr[2] = 3
arr[3] = 4
arr[4] = 5
arr[5] = 6
arr[6] = 7
arr[7] = 8
"


This is the output of
objdump -x a.out (after stripping)

"
a.out:     file format elf64-x86-64
a.out
architecture: i386:x86-64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000400450

....
Lots of segments.

 23 .got.plt      00000030  0000000000600900  0000000000600900  00000900  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 24 .data         00000040  0000000000600940  0000000000600940  00000940  2**5
                  CONTENTS, ALLOC, LOAD, DATA
 25 .bss          00000010  0000000000600980  0000000000600980  00000980  2**3
                  ALLOC
 26 .comment      0000001c  0000000000000000  0000000000000000  00000980  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
no symbols
"

Look at .data It is CONTENTS LOAD DATA, i.e. it has content
in the executable binary and this is loaded as such into memory
at startup.

You can also ask to dump the content of the sections:

objdump -s a.out


a.out:     file format elf64-x86-64

...

Contents of section .data:
 600940 00000000 00000000 00000000 00000000  ................
 600950 00000000 00000000 00000000 00000000  ................
 600960 01000000 02000000 03000000 04000000  ................
 600970 05000000 06000000 07000000 08000000  ................
Contents of section .comment:
 0000 4743433a 20284465 6269616e 20342e34  GCC: (Debian 4.4
 0010 2e352d38 2920342e 342e3500           .5-8) 4.4.5.



>
>
>>
>> --
>> Steven
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>-=-=-=-=-=-
>[Alternative: text/html]
>-=-=-=-=-=-
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list