본문 바로가기
OldStory/WORKS

main함수 없이 프로그램 짜기

by Alnilam 2010. 6. 30.

statup code관련하여 crt0.S를 보면 _start 라는 셋션으로 시작 하는 것를 볼 수 있다.
이를 이용하면 main함수 없이 프로그램을 작성할 수 있다.

다음은 그 예제 소스이다.

#include <stdio.h>
#include <unistd.h>
_start()
{
        _exit(my_number(7));
}
int my_number(int x)
{
        printf("My favorite number is %dn", x);
        return 1;
}

리눅스에서 다음과 같이 컴파일 하고 실행 해 볼 수 있다.

$ gcc -nostartfiles test.c
$./a.out
My favorite number is 7.
$  echo $?
1
$

'OldStory > WORKS' 카테고리의 다른 글

section  (0) 2010.07.02
어셈블러 확장자  (0) 2010.07.01
startup code  (0) 2010.06.29
_sbrk_r  (0) 2010.06.24
printf  (0) 2010.06.09