リスト52 リスト53


〔リスト52〕constructor属性を使用した例(test76.c)
	#include <stdio.h>
	void init_proc ()  __attribute__ ((constructor ));
	int temp = 100;
	int main(void)
	{
	 printf("start\n");
	 printf("temp=%d\n",temp);
	 return;
	}
	void init_proc()
	{
	 temp = 10;1
	 return;
	}


〔リスト53〕test76.cから生成されたアセンブラ(test76.s)
	 .file "test76.c"
	 .version "01.01"
	gcc2_compiled.:
	.globl temp
	.data
	 .align 4
	 .type  temp,@object
	 .size  temp,4
	temp:
	 .long 100
	.section .rodata
	.LC0:
	 .string "start\n"
	.LC1:
	 .string "temp=%d\n"
	.section .ctors,"aw"
	 .long  init_proc
	.text
	 .align 4
	.globl init_proc
	 .type  init_proc,@function
	init_proc:
	 pushl %ebp
	 movl %esp,%ebp
	 movl $10,temp
	 movl %ebp,%esp
	 popl %ebp
	 ret
	.Lfe1:
	 .size  init_proc,.Lfe1-init_proc
	 .align 4
	.globl main
	 .type  main,@function
	main:
	 pushl %ebp
	 movl %esp,%ebp
	 subl $8,%esp
	 addl $-12,%esp
	 pushl $.LC0
	 call printf
	 movl temp,%eax
	 addl $-8,%esp
	 pushl %eax
	 pushl $.LC1
	 call printf
	 movl %ebp,%esp
	 popl %ebp
	 ret
	.Lfe2:
	 .size  main,.Lfe2-main
	 .ident "GCC: (GNU) 2.95.3 20010315 (release)"