진짜 기초적인 C 질문좀 드리겠습니다 ㅠ
글쓴이: sacredone / 작성시간: 금, 2012/11/16 - 11:19오전
에휴...
아직까지 기초적인거나 물어보는제가 한심하지만;;
기초가 탄탄하지 않나봅니다 ㅠㅠ
먼저 제가 지금까지 쓰던 구조체 정의와 선언에 대해서 말씀드리면
typedef struct 아무이름{
멤버 1;
멤버 2;
}test_t;
int main()
{
test_t t1;
}이렇게 정의하고 선언해서 사용했습니다
이렇게 쓰면서 제가 이해하기로는
"아무이름은 사실 의미없는거고 컴파일러에 따라 없으면 경고할수도있기 때문에 사용하고
실제로 나는 test_t 라는 이름으로 사용한다"
라고 생각하고 썼었는데
오늘 선배한테 듣기로 구조체 정의할때 이러더라구요
"구조체 사용할때 typedef 사용하던대로 사용해도되지만 별로 추천하지 않는다
나는 개인적으로 typedef 해서 사용하면 이게 실제하는건지 정의한건지 헷갈려서
어차피 한번 선언할거 그냥 struct ~ 쓴다. 이렇게되있으면 그냥 위에서 확인하면 되기때문에"
이러더라구요
전 이렇게 헷갈릴까봐 typedef 하고 타입이름을 test_t 처럼 언더바 t를 붙이는데
들어보니 struct 도 쓰는것도 나쁘지않을거같더라구요 typedef 안하고...
그래서 한번 그런스타일로 짜보려고했는데 궁금한점이 생겼습니다
typedef struct 아무이름 {
}test_t;
하면 [struct 아무이름 변수이름;] 으로 선언할꺼 [test_t 변수이름;] 이렇게 선언할수 있게되는건데
typdef 빼고
struct 아무이름 {
}test_t;
하면 struct 아무이름 변수이름; 으로 변수가 선언되고 test_t 는 어떻게되는건가요?
Forums:


기초가 탄탄하지 않다면 문법서를 다시 보시는 걸 추천합니다.
#include <stdio.h> // struct _test1 정의 struct _test1 { int x; }; // struct _test2를 정의하면서 struct _test2_var1 변수 선언 struct _test2 { int x; } test2_var1; // struct _test3를 정의하면서 struct _test3를 Test3 타입으로 정의함 typedef struct _test3 { int x; } Test3; // main int main(void) { struct _test1 test1_var; struct _test2 test2_var2; struct _test3 test3_var1; Test3 test3_var2; test1_var.x = 10; test2_var1.x = 10; test2_var2.x = 10; test3_var1.x = 10; test3_var2.x = 10; return 0; }저는 이렇게 생각했습니다.
즉 typedef struct {} ~~~~ 여기서
즉 typedef struct {} ~~~~
여기서 물결에 들어갈것은 재정의 하는것이고
struct {} ~~~~
여기서 물결에 들어가는것은 실제로 변수를 선언하는 것인가요?
그렇게 되지요.
위에 달린 답글을 편집하려하였으나... 막혔네요. ㅎㅎ
내용이 추가된 코드입니다.
#include <stdio.h> // struct _test1 정의 struct _test1 { int x; }; // struct _test2를 정의하면서 struct _test2_var1 변수 선언 struct _test2 { int x; } test2_var1; // struct _test3를 정의하면서 struct _test3를 Test3 타입으로 정의함 typedef struct _test3 { int x; } Test3; // 이름 없는 구조체를 정의하면서 test4_var 변수 선언 struct { int x; } test4_var; // 이름 없는 구조체를 정의하면서 이 구조체를 Test5 타입으로 정의함 typedef struct { int x; } Test5; // main int main(void) { struct _test1 test1_var; struct _test2 test2_var2; struct _test3 test3_var1; Test3 test3_var2; // test4_var에 대한 구조체는 더 생성할 수 없다 Test5 test5_var; test1_var.x = 10; test2_var1.x = 10; test2_var2.x = 10; test3_var1.x = 10; test3_var2.x = 10; test4_var.x = 10; test5_var.x = 10; return 0; }저는 이렇게 생각했습니다.
지나가다..
c가발목잡는다면 다른것을 하는게 더 낫습니다.
--------------------------------------------------------------------------------
open source, open teaching, 천기누설이 꿈~ 은 개뿔...
--------------------------------------------------------------------------------
어떻게 이런 쓰레기만도 못한 사상을 가지고 계신지
어떻게 이런 쓰레기만도 못한 사상을 가지고 계신지 궁금할 따름입니다.
이런 댓글에 아무 답글도 달리지 않는 걸 보면 KLDP도 이젠 너무 무심해진 걸까요.
그보다는 Don't feed this troll
그보다는 Don't feed this troll 원칙이 잘 지켜지고 있다고 생각합니다.
피할 수 있을때 즐겨라! http://melotopia.net/b
>> "구조체 사용할때 typedef 사용하던대로
>> "구조체 사용할때 typedef 사용하던대로 사용해도되지만 별로 추천하지 않는다 나는 개인적으로 typedef 해서 사용하면 이게 실제하는건지 정의한건지 헷갈려서 어차피 한번 선언할거 그냥 struct ~ 쓴다. 이렇게되있으면 그냥 위에서 확인하면 되기때문에"
그 선배 말은 그냥 무시하세요. 말씀하신 형태로 typedef를 사용하는 것은 널리 쓰이고 있고 별 단점도 없습니다
다들. 선언과 정의가 반대예요
많은 사이트들이 이상한 내용인데요.
책에 제대로 된 내용이 있습니다.
http://bestheroz.blog.me/89563691
http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=70278966&qb=dHlwZWRlZiDsgqzsmqntlZjrjZjrjIDroZw=&enc=utf8§ion=kin&rank=3&search_sort=0&spq=0&pid=R6UF3U5Y7uwssa0aMXwssssssul-407300&sid=UKXn3XJvLCwAAF0FJmA
----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
변수의 선언과 구조체의 선언은 다른 것인지요?
int형 변수의 경우는 int num;이라고 하면 "num 변수를 선언한다"라고 표현해야 하는 줄로 알고 있습니다.
그래서 struct 키워드를 이용해 만든 구조체의 경우에도 변수로 만든다고 하면 "선언한다"가 맞고
구조체의 모양을 결정하는 것은 선언과는 다른 것이니 정의가 적당하다고 생각하고 있었는데요.
"구조체의 선언"과 "구조체 변수의 선언"의 차이를 말씀하시는지요?
답변 감사합니다.
저는 이렇게 생각했습니다.
선언이라는 점에서 동일하나 형태가 다릅니다.
짧은 지식으로 대신 답글을 달아봅니다.
C언어에서의 선언이란 컴파일러에게 해당 명칭을 사용하겠다고 알려주는 것이 목적입니다. 즉, 메모리의 실체를 동반하지 않습니다. 또한 C언어에서 정의라는 것은 일반적인 "구조체의 모양을 정의하다"라고 할 때의 그 정의를 의미하는 것이 아니라 공간확보(메모리 할당 같은)와 메모리 상에 내용을 채워 넣넣는 것을 의미하는 것으로 알고 있습니다.
많은 경우 (가장 흔한 auto 형태의 변수 선언) 선언과 정의가 동시에 일어날 수 있습니다.
말씀하신바와 같이 int num; 이라는 변수 선언은 컴파일러에게 num이라는 이름을 사용하겠다고 알리며, 별도의 정의 과정 없이 컴파일러는 해당 명칭에 대하여
num이라는 이름에 대한 어떤 주소값을 할당하고 num에 값을 넣는 것이 가능하도록 합니다.
일반적인 변수 선언에서 선언과 정의가 분리되는 경우의 간단한 예는 extern을 사용하는 경우입니다.
A.c라는 파일에서 int num;을 전역으로 선언하고, B.c에서 extern int num;을 이용하는 경우 A.c에서는 int num;을 선언하면서 정의(메모리 공간 확보)가 일어났으나 B.c에서는 num이라는 이름을 사용하겠다고 알리기만 할 뿐 메모리 할당은 A.c 에서 발생한 것을 그대로 공유하여 사용합니다. 즉, 정의는 별도로 일어나지 않습니다.
struct의 경우도 위의 int로 예를 든것과 마찬가지입니다. 대부분의 경우 흔히 우리가 변수를 선언한다 라고 말하는 것들에서 선언과 정의가 동시에 발생하는 것이며,
말씀하신 struct의 모양을 정의하는 것 역시 그런 모양을 사용하겠다고 컴파일러에게 알리는 작업이므로 이 또한 struct 태그 선언이라고 말합니다.
답변 감사합니다.
잘못 알고 있던 것을 고쳐가네요.
감사합니다. ㅎㅎ
저는 이렇게 생각했습니다.
지금 책이 없어서 100% 정확한 내용은
지금 책이 없어서 100% 정확한 내용은 아니지만,
점점 결론이 잘못된 방향으로 가는 것 같아서 답글 붙여봅니다.
일단 웹상에서 찾은 선언/정의에 관한 자료 중 믿을만한 자료는 여기
http://www.cprogramming.com/declare_vs_define.html
대강 요약하면,
정의는 어떤 object( function, class, variable 등등) 의 모든 attribute를 기술하는 것이고,
선언은 그 중 (컴파일 등을 위해) 필요한 일부(타입과 이름)를 기술하는 것을 의미한다.
( 보다 정확한 차이점은 다른 분께서.. )
따라서 정의도 자동적으로 선언이 되죠.. 선언은 정의가 될 수 없고요..
shint님이 답글로 다신 첫번째 링크는 "struct"의 정의와 "변수"의 정의를
섞어서 완전히 잘못 설명하고 있더군요..
struct x {int i;};
는 struct x 라는 새로운 "타입"을 정의하는 것이고,
struct {int i;} x;
는 이름없는 struct 타입의 "변수" x를 정의하는 것입니다.
struct x;
이것은 struct x라는 struct 타입을 선언하는 것이고요.
주로 전방선언에서 사용됩니다.
..
C와 C++은 각각의 표준이 따로 존재하며 각 표준에서 말하는 declaration과 definition은 미묘한 차이가 있어보입니다.
C표준인 C99에서는 struct x { int i; };와 같은 것은 Tag에 대한 declaration(선언)에 해당하는 것으로 알고 있습니다.
(C99 표준 6.7.2.3 Tags 절 참조)
이러한 미묘한 차이의 대표적인 예로는 typedef가 있을 수 있습니다. typedef의 경우 C++에서는 선언에 해당하지만 C에서는 정의에 해당합니다.
말씀하신 내용이
말씀하신 내용이 정확하네요
http://bytes.com/topic/c/answers/220110-declaration-vs-definitio
가 제가 현재까지 찾은 자료 중 가장 깊이 있는 논의입니다. 특히 아래에서 두번째.
말씀하신 표준도 적절히 인용되고 있고요..
그러면 c에서는 "structure definition"은 없는거네요,
"Defining" declaration 이라고 부를 수는 있겠네요.
좋은 정보 감사합니다.
확인한 내용입니다.
좀 깁니다.
Visual C 디버깅 c cpp랑
gdb 덤프 gcc g++ 내용입니다.
말씀 하시는 내용을 이해하기 어려워서. 그냥 소스 디버깅 결과를 떠왔습니다.
http://blog.naver.com/my_1028?Redirect=Log&logNo=50014525423
http://www.villa4u.co.kr/jbn/bbs/board.php?bo_table=clp2&wr_id=29
http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=63837765&qb=7ZSE66Gc6re4656oIOyEoOyWuA==&enc=utf8§ion=kin&rank=1&search_sort=0&spq=0
//참고용
http://kldp.org/node/114775
#include <stdio.h> int a; int b=0; void fn1(); struct { int a; }ST1; typedef struct { int a; }ST2; typedef struct DF_ST { int a; }ST3; void fn2() { printf("fn2\n"); } void main() { int c; int d=0; printf("shint\n"); } void fn1() { printf("fn1\n"); } void fn3() { printf("fn2\n"); } --- C:\Documents and Settings\shint\바탕 화면\main.c ------------------------------------------------------------------------------------- 27: 28: void main() 29: { 0040D710 push ebp 0040D711 mov ebp,esp 0040D713 sub esp,48h 0040D716 push ebx 0040D717 push esi 0040D718 push edi 0040D719 lea edi,[ebp-48h] 0040D71C mov ecx,12h 0040D721 mov eax,0CCCCCCCCh 0040D726 rep stos dword ptr [edi] 30: int c; 31: int d=0; 0040D728 mov dword ptr [ebp-8],0 32: 33: printf("shint\n"); 0040D72F push offset string "shint\n" (00422fa4) 0040D734 call printf (0040d690) 0040D739 add esp,4 34: } 0040D73C pop edi 0040D73D pop esi 0040D73E pop ebx 0040D73F add esp,48h 0040D742 cmp ebp,esp 0040D744 call __chkesp (0040d650) 0040D749 mov esp,ebp 0040D74B pop ebp 0040D74C ret --- No source file ----------------------------------------------------------------------------------------------------------------------- 0040D74D int 3 0040D74E int 3 0040D74F int 3 --- C:\Documents and Settings\shint\바탕 화면\main.c ------------------------------------------------------------------------------------- 35: 36: void fn1() 37: { 0040D750 push ebp 0040D751 mov ebp,esp 0040D753 sub esp,40h 0040D756 push ebx 0040D757 push esi 0040D758 push edi 0040D759 lea edi,[ebp-40h] 0040D75C mov ecx,10h 0040D761 mov eax,0CCCCCCCCh 0040D766 rep stos dword ptr [edi] 38: printf("fn1\n"); 0040D768 push offset string "fn1\n" (00422fac) 0040D76D call printf (0040d690) 0040D772 add esp,4 39: } 0040D775 pop edi 0040D776 pop esi 0040D777 pop ebx 0040D778 add esp,40h 0040D77B cmp ebp,esp 0040D77D call __chkesp (0040d650) 0040D782 mov esp,ebp 0040D784 pop ebp 0040D785 ret --- No source file ----------------------------------------------------------------------------------------------------------------------- 0040D786 int 3 0040D787 int 3 0040D788 int 3 0040D789 int 3 0040D78A int 3 0040D78B int 3 0040D78C int 3 0040D78D int 3 0040D78E int 3 0040D78F int 3 --- C:\Documents and Settings\shint\바탕 화면\main.c ------------------------------------------------------------------------------------- 40: 41: 42: void fn3() 43: { 0040D790 push ebp 0040D791 mov ebp,esp 0040D793 sub esp,40h 0040D796 push ebx 0040D797 push esi 0040D798 push edi 0040D799 lea edi,[ebp-40h] 0040D79C mov ecx,10h 0040D7A1 mov eax,0CCCCCCCCh 0040D7A6 rep stos dword ptr [edi] 44: printf("fn2\n"); 0040D7A8 push offset string "fn2\n" (00422e80) 0040D7AD call printf (0040d690) 0040D7B2 add esp,4 45: } 0040D7B5 pop edi 0040D7B6 pop esi 0040D7B7 pop ebx 0040D7B8 add esp,40h 0040D7BB cmp ebp,esp 0040D7BD call __chkesp (0040d650) 0040D7C2 mov esp,ebp 0040D7C4 pop ebp 0040D7C5 ret --- c:\documents and settings\shint\바탕 화면\main.cpp ----------------------------------------------------------------------------------- 27: 28: void main() 29: { 0040D710 push ebp 0040D711 mov ebp,esp 0040D713 sub esp,48h 0040D716 push ebx 0040D717 push esi 0040D718 push edi 0040D719 lea edi,[ebp-48h] 0040D71C mov ecx,12h 0040D721 mov eax,0CCCCCCCCh 0040D726 rep stos dword ptr [edi] 30: int c; 31: int d=0; 0040D728 mov dword ptr [ebp-8],0 32: 33: printf("shint\n"); 0040D72F push offset string "shint\n" (00422fa4) 0040D734 call printf (0040d690) 0040D739 add esp,4 34: } 0040D73C pop edi 0040D73D pop esi 0040D73E pop ebx 0040D73F add esp,48h 0040D742 cmp ebp,esp 0040D744 call __chkesp (0040d650) 0040D749 mov esp,ebp 0040D74B pop ebp 0040D74C ret --- No source file ----------------------------------------------------------------------------------------------------------------------- 0040D74D int 3 0040D74E int 3 0040D74F int 3 --- c:\documents and settings\shint\바탕 화면\main.cpp ----------------------------------------------------------------------------------- 35: 36: void fn1() 37: { 0040D750 push ebp 0040D751 mov ebp,esp 0040D753 sub esp,40h 0040D756 push ebx 0040D757 push esi 0040D758 push edi 0040D759 lea edi,[ebp-40h] 0040D75C mov ecx,10h 0040D761 mov eax,0CCCCCCCCh 0040D766 rep stos dword ptr [edi] 38: printf("fn1\n"); 0040D768 push offset string "fn1\n" (00422fac) 0040D76D call printf (0040d690) 0040D772 add esp,4 39: } 0040D775 pop edi 0040D776 pop esi 0040D777 pop ebx 0040D778 add esp,40h 0040D77B cmp ebp,esp 0040D77D call __chkesp (0040d650) 0040D782 mov esp,ebp 0040D784 pop ebp 0040D785 ret --- No source file ----------------------------------------------------------------------------------------------------------------------- 0040D786 int 3 0040D787 int 3 0040D788 int 3 0040D789 int 3 0040D78A int 3 0040D78B int 3 0040D78C int 3 0040D78D int 3 0040D78E int 3 0040D78F int 3 --- c:\documents and settings\shint\바탕 화면\main.cpp ----------------------------------------------------------------------------------- 40: 41: 42: void fn3() 43: { 0040D790 push ebp 0040D791 mov ebp,esp 0040D793 sub esp,40h 0040D796 push ebx 0040D797 push esi 0040D798 push edi 0040D799 lea edi,[ebp-40h] 0040D79C mov ecx,10h 0040D7A1 mov eax,0CCCCCCCCh 0040D7A6 rep stos dword ptr [edi] 44: printf("fn2\n"); 0040D7A8 push offset string "fn2\n" (00422e80) 0040D7AD call printf (0040d690) 0040D7B2 add esp,4 45: } 0040D7B5 pop edi 0040D7B6 pop esi 0040D7B7 pop ebx 0040D7B8 add esp,40h 0040D7BB cmp ebp,esp 0040D7BD call __chkesp (0040d650) 0040D7C2 mov esp,ebp 0040D7C4 pop ebp 0040D7C5 ret //------------------------------------------------------------------------------------------------ //GCC .c //------------------------------------------------------------------------------------------------ main: file format elf32-i386 Disassembly of section .init: 08048290 <_init>: 8048290: 55 push %ebp 8048291: 89 e5 mov %esp,%ebp 8048293: 53 push %ebx 8048294: 83 ec 04 sub $0x4,%esp 8048297: e8 00 00 00 00 call 804829c <_init+0xc> 804829c: 5b pop %ebx 804829d: 81 c3 c8 13 00 00 add $0x13c8,%ebx 80482a3: 8b 93 fc ff ff ff mov -0x4(%ebx),%edx 80482a9: 85 d2 test %edx,%edx 80482ab: 74 05 je 80482b2 <_init+0x22> 80482ad: e8 1e 00 00 00 call 80482d0 <__gmon_start__@plt> 80482b2: e8 d9 00 00 00 call 8048390 <frame_dummy> 80482b7: e8 c4 01 00 00 call 8048480 <__do_global_ctors_aux> 80482bc: 58 pop %eax 80482bd: 5b pop %ebx 80482be: c9 leave 80482bf: c3 ret Disassembly of section .plt: 080482c0 <__gmon_start__@plt-0x10>: 80482c0: ff 35 68 96 04 08 pushl 0x8049668 80482c6: ff 25 6c 96 04 08 jmp *0x804966c 80482cc: 00 00 add %al,(%eax) ... 080482d0 <__gmon_start__@plt>: 80482d0: ff 25 70 96 04 08 jmp *0x8049670 80482d6: 68 00 00 00 00 push $0x0 80482db: e9 e0 ff ff ff jmp 80482c0 <_init+0x30> 080482e0 <__libc_start_main@plt>: 80482e0: ff 25 74 96 04 08 jmp *0x8049674 80482e6: 68 08 00 00 00 push $0x8 80482eb: e9 d0 ff ff ff jmp 80482c0 <_init+0x30> 080482f0 <puts@plt>: 80482f0: ff 25 78 96 04 08 jmp *0x8049678 80482f6: 68 10 00 00 00 push $0x10 80482fb: e9 c0 ff ff ff jmp 80482c0 <_init+0x30> Disassembly of section .text: 08048300 <_start>: 8048300: 31 ed xor %ebp,%ebp 8048302: 5e pop %esi 8048303: 89 e1 mov %esp,%ecx 8048305: 83 e4 f0 and $0xfffffff0,%esp 8048308: 50 push %eax 8048309: 54 push %esp 804830a: 52 push %edx 804830b: 68 10 84 04 08 push $0x8048410 8048310: 68 20 84 04 08 push $0x8048420 8048315: 51 push %ecx 8048316: 56 push %esi 8048317: 68 c8 83 04 08 push $0x80483c8 804831c: e8 bf ff ff ff call 80482e0 <__libc_start_main@plt> 8048321: f4 hlt 8048322: 90 nop 8048323: 90 nop 8048324: 90 nop 8048325: 90 nop 8048326: 90 nop 8048327: 90 nop 8048328: 90 nop 8048329: 90 nop 804832a: 90 nop 804832b: 90 nop 804832c: 90 nop 804832d: 90 nop 804832e: 90 nop 804832f: 90 nop 08048330 <__do_global_dtors_aux>: 8048330: 55 push %ebp 8048331: 89 e5 mov %esp,%ebp 8048333: 53 push %ebx 8048334: 8d 64 24 fc lea -0x4(%esp),%esp 8048338: 80 3d 80 96 04 08 00 cmpb $0x0,0x8049680 804833f: 75 3e jne 804837f <__do_global_dtors_aux+0x4f> 8048341: bb 90 95 04 08 mov $0x8049590,%ebx 8048346: a1 84 96 04 08 mov 0x8049684,%eax 804834b: 81 eb 8c 95 04 08 sub $0x804958c,%ebx 8048351: c1 fb 02 sar $0x2,%ebx 8048354: 83 eb 01 sub $0x1,%ebx 8048357: 39 d8 cmp %ebx,%eax 8048359: 73 1d jae 8048378 <__do_global_dtors_aux+0x48> 804835b: 90 nop 804835c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 8048360: 83 c0 01 add $0x1,%eax 8048363: a3 84 96 04 08 mov %eax,0x8049684 8048368: ff 14 85 8c 95 04 08 call *0x804958c(,%eax,4) 804836f: a1 84 96 04 08 mov 0x8049684,%eax 8048374: 39 d8 cmp %ebx,%eax 8048376: 72 e8 jb 8048360 <__do_global_dtors_aux+0x30> 8048378: c6 05 80 96 04 08 01 movb $0x1,0x8049680 804837f: 8d 64 24 04 lea 0x4(%esp),%esp 8048383: 5b pop %ebx 8048384: 5d pop %ebp 8048385: c3 ret 8048386: 8d 76 00 lea 0x0(%esi),%esi 8048389: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 08048390 <frame_dummy>: 8048390: 55 push %ebp 8048391: 89 e5 mov %esp,%ebp 8048393: 8d 64 24 e8 lea -0x18(%esp),%esp 8048397: a1 94 95 04 08 mov 0x8049594,%eax 804839c: 85 c0 test %eax,%eax 804839e: 74 12 je 80483b2 <frame_dummy+0x22> 80483a0: b8 00 00 00 00 mov $0x0,%eax 80483a5: 85 c0 test %eax,%eax 80483a7: 74 09 je 80483b2 <frame_dummy+0x22> 80483a9: c7 04 24 94 95 04 08 movl $0x8049594,(%esp) 80483b0: ff d0 call *%eax 80483b2: c9 leave 80483b3: c3 ret 080483b4 <fn2>: { int a; }ST3; void fn2() { 80483b4: 55 push %ebp 80483b5: 89 e5 mov %esp,%ebp 80483b7: 83 ec 18 sub $0x18,%esp printf("fn2\n"); 80483ba: c7 04 24 d4 84 04 08 movl $0x80484d4,(%esp) 80483c1: e8 2a ff ff ff call 80482f0 <puts@plt> } 80483c6: c9 leave 80483c7: c3 ret 080483c8 <main>: void main() { 80483c8: 55 push %ebp 80483c9: 89 e5 mov %esp,%ebp 80483cb: 83 e4 f0 and $0xfffffff0,%esp 80483ce: 83 ec 20 sub $0x20,%esp int c; int d=0; 80483d1: c7 44 24 1c 00 00 00 movl $0x0,0x1c(%esp) 80483d8: 00 printf("shint\n"); 80483d9: c7 04 24 d8 84 04 08 movl $0x80484d8,(%esp) 80483e0: e8 0b ff ff ff call 80482f0 <puts@plt> } 80483e5: c9 leave 80483e6: c3 ret 080483e7 <fn1>: void fn1() { 80483e7: 55 push %ebp 80483e8: 89 e5 mov %esp,%ebp 80483ea: 83 ec 18 sub $0x18,%esp printf("fn1\n"); 80483ed: c7 04 24 de 84 04 08 movl $0x80484de,(%esp) 80483f4: e8 f7 fe ff ff call 80482f0 <puts@plt> } 80483f9: c9 leave 80483fa: c3 ret 080483fb <fn3>: void fn3() { 80483fb: 55 push %ebp 80483fc: 89 e5 mov %esp,%ebp 80483fe: 83 ec 18 sub $0x18,%esp printf("fn2\n"); 8048401: c7 04 24 d4 84 04 08 movl $0x80484d4,(%esp) 8048408: e8 e3 fe ff ff call 80482f0 <puts@plt> } 804840d: c9 leave 804840e: c3 ret 804840f: 90 nop 08048410 <__libc_csu_fini>: 8048410: 55 push %ebp 8048411: 89 e5 mov %esp,%ebp 8048413: 5d pop %ebp 8048414: c3 ret 8048415: 66 66 2e 0f 1f 84 00 nopw %cs:0x0(%eax,%eax,1) 804841c: 00 00 00 00 08048420 <__libc_csu_init>: 8048420: 55 push %ebp 8048421: 89 e5 mov %esp,%ebp 8048423: 57 push %edi 8048424: 56 push %esi 8048425: 53 push %ebx 8048426: e8 4f 00 00 00 call 804847a <__i686.get_pc_thunk.bx> 804842b: 81 c3 39 12 00 00 add $0x1239,%ebx 8048431: 83 ec 1c sub $0x1c,%esp 8048434: e8 57 fe ff ff call 8048290 <_init> 8048439: 8d bb 20 ff ff ff lea -0xe0(%ebx),%edi 804843f: 8d 83 20 ff ff ff lea -0xe0(%ebx),%eax 8048445: 29 c7 sub %eax,%edi 8048447: c1 ff 02 sar $0x2,%edi 804844a: 85 ff test %edi,%edi 804844c: 74 24 je 8048472 <__libc_csu_init+0x52> 804844e: 31 f6 xor %esi,%esi 8048450: 8b 45 10 mov 0x10(%ebp),%eax 8048453: 89 44 24 08 mov %eax,0x8(%esp) 8048457: 8b 45 0c mov 0xc(%ebp),%eax 804845a: 89 44 24 04 mov %eax,0x4(%esp) 804845e: 8b 45 08 mov 0x8(%ebp),%eax 8048461: 89 04 24 mov %eax,(%esp) 8048464: ff 94 b3 20 ff ff ff call *-0xe0(%ebx,%esi,4) 804846b: 83 c6 01 add $0x1,%esi 804846e: 39 fe cmp %edi,%esi 8048470: 72 de jb 8048450 <__libc_csu_init+0x30> 8048472: 83 c4 1c add $0x1c,%esp 8048475: 5b pop %ebx 8048476: 5e pop %esi 8048477: 5f pop %edi 8048478: 5d pop %ebp 8048479: c3 ret 0804847a <__i686.get_pc_thunk.bx>: 804847a: 8b 1c 24 mov (%esp),%ebx 804847d: c3 ret 804847e: 90 nop 804847f: 90 nop 08048480 <__do_global_ctors_aux>: 8048480: 55 push %ebp 8048481: 89 e5 mov %esp,%ebp 8048483: 53 push %ebx 8048484: 8d 64 24 fc lea -0x4(%esp),%esp 8048488: a1 84 95 04 08 mov 0x8049584,%eax 804848d: 83 f8 ff cmp $0xffffffff,%eax 8048490: 74 12 je 80484a4 <__do_global_ctors_aux+0x24> 8048492: bb 84 95 04 08 mov $0x8049584,%ebx 8048497: 90 nop 8048498: 8d 5b fc lea -0x4(%ebx),%ebx 804849b: ff d0 call *%eax 804849d: 8b 03 mov (%ebx),%eax 804849f: 83 f8 ff cmp $0xffffffff,%eax 80484a2: 75 f4 jne 8048498 <__do_global_ctors_aux+0x18> 80484a4: 8d 64 24 04 lea 0x4(%esp),%esp 80484a8: 5b pop %ebx 80484a9: 5d pop %ebp 80484aa: c3 ret 80484ab: 90 nop Disassembly of section .fini: 080484ac <_fini>: 80484ac: 55 push %ebp 80484ad: 89 e5 mov %esp,%ebp 80484af: 53 push %ebx 80484b0: 83 ec 04 sub $0x4,%esp 80484b3: e8 00 00 00 00 call 80484b8 <_fini+0xc> 80484b8: 5b pop %ebx 80484b9: 81 c3 ac 11 00 00 add $0x11ac,%ebx 80484bf: e8 6c fe ff ff call 8048330 <__do_global_dtors_aux> 80484c4: 59 pop %ecx 80484c5: 5b pop %ebx 80484c6: c9 leave 80484c7: c3 ret //------------------------------------------------------------------------------------------------ //G++ .cpp //------------------------------------------------------------------------------------------------ main2: file format elf32-i386 Disassembly of section .init: 0804833c <_init>: 804833c: 55 push %ebp 804833d: 89 e5 mov %esp,%ebp 804833f: 53 push %ebx 8048340: 83 ec 04 sub $0x4,%esp 8048343: e8 00 00 00 00 call 8048348 <_init+0xc> 8048348: 5b pop %ebx 8048349: 81 c3 c0 14 00 00 add $0x14c0,%ebx 804834f: 8b 93 fc ff ff ff mov -0x4(%ebx),%edx 8048355: 85 d2 test %edx,%edx 8048357: 74 05 je 804835e <_init+0x22> 8048359: e8 1e 00 00 00 call 804837c <__gmon_start__@plt> 804835e: e8 ed 00 00 00 call 8048450 <frame_dummy> 8048363: e8 e8 01 00 00 call 8048550 <__do_global_ctors_aux> 8048368: 58 pop %eax 8048369: 5b pop %ebx 804836a: c9 leave 804836b: c3 ret Disassembly of section .plt: 0804836c <__gmon_start__@plt-0x10>: 804836c: ff 35 0c 98 04 08 pushl 0x804980c 8048372: ff 25 10 98 04 08 jmp *0x8049810 8048378: 00 00 add %al,(%eax) ... 0804837c <__gmon_start__@plt>: 804837c: ff 25 14 98 04 08 jmp *0x8049814 8048382: 68 00 00 00 00 push $0x0 8048387: e9 e0 ff ff ff jmp 804836c <_init+0x30> 0804838c <__libc_start_main@plt>: 804838c: ff 25 18 98 04 08 jmp *0x8049818 8048392: 68 08 00 00 00 push $0x8 8048397: e9 d0 ff ff ff jmp 804836c <_init+0x30> 0804839c <puts@plt>: 804839c: ff 25 1c 98 04 08 jmp *0x804981c 80483a2: 68 10 00 00 00 push $0x10 80483a7: e9 c0 ff ff ff jmp 804836c <_init+0x30> 080483ac <__gxx_personality_v0@plt>: 80483ac: ff 25 20 98 04 08 jmp *0x8049820 80483b2: 68 18 00 00 00 push $0x18 80483b7: e9 b0 ff ff ff jmp 804836c <_init+0x30> Disassembly of section .text: 080483c0 <_start>: 80483c0: 31 ed xor %ebp,%ebp 80483c2: 5e pop %esi 80483c3: 89 e1 mov %esp,%ecx 80483c5: 83 e4 f0 and $0xfffffff0,%esp 80483c8: 50 push %eax 80483c9: 54 push %esp 80483ca: 52 push %edx 80483cb: 68 e0 84 04 08 push $0x80484e0 80483d0: 68 f0 84 04 08 push $0x80484f0 80483d5: 51 push %ecx 80483d6: 56 push %esi 80483d7: 68 88 84 04 08 push $0x8048488 80483dc: e8 ab ff ff ff call 804838c <__libc_start_main@plt> 80483e1: f4 hlt 80483e2: 90 nop 80483e3: 90 nop 80483e4: 90 nop 80483e5: 90 nop 80483e6: 90 nop 80483e7: 90 nop 80483e8: 90 nop 80483e9: 90 nop 80483ea: 90 nop 80483eb: 90 nop 80483ec: 90 nop 80483ed: 90 nop 80483ee: 90 nop 80483ef: 90 nop 080483f0 <__do_global_dtors_aux>: 80483f0: 55 push %ebp 80483f1: 89 e5 mov %esp,%ebp 80483f3: 53 push %ebx 80483f4: 8d 64 24 fc lea -0x4(%esp),%esp 80483f8: 80 3d 28 98 04 08 00 cmpb $0x0,0x8049828 80483ff: 75 3e jne 804843f <__do_global_dtors_aux+0x4f> 8048401: bb 1c 97 04 08 mov $0x804971c,%ebx 8048406: a1 2c 98 04 08 mov 0x804982c,%eax 804840b: 81 eb 18 97 04 08 sub $0x8049718,%ebx 8048411: c1 fb 02 sar $0x2,%ebx 8048414: 83 eb 01 sub $0x1,%ebx 8048417: 39 d8 cmp %ebx,%eax 8048419: 73 1d jae 8048438 <__do_global_dtors_aux+0x48> 804841b: 90 nop 804841c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 8048420: 83 c0 01 add $0x1,%eax 8048423: a3 2c 98 04 08 mov %eax,0x804982c 8048428: ff 14 85 18 97 04 08 call *0x8049718(,%eax,4) 804842f: a1 2c 98 04 08 mov 0x804982c,%eax 8048434: 39 d8 cmp %ebx,%eax 8048436: 72 e8 jb 8048420 <__do_global_dtors_aux+0x30> 8048438: c6 05 28 98 04 08 01 movb $0x1,0x8049828 804843f: 8d 64 24 04 lea 0x4(%esp),%esp 8048443: 5b pop %ebx 8048444: 5d pop %ebp 8048445: c3 ret 8048446: 8d 76 00 lea 0x0(%esi),%esi 8048449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 08048450 <frame_dummy>: 8048450: 55 push %ebp 8048451: 89 e5 mov %esp,%ebp 8048453: 8d 64 24 e8 lea -0x18(%esp),%esp 8048457: a1 20 97 04 08 mov 0x8049720,%eax 804845c: 85 c0 test %eax,%eax 804845e: 74 12 je 8048472 <frame_dummy+0x22> 8048460: b8 00 00 00 00 mov $0x0,%eax 8048465: 85 c0 test %eax,%eax 8048467: 74 09 je 8048472 <frame_dummy+0x22> 8048469: c7 04 24 20 97 04 08 movl $0x8049720,(%esp) 8048470: ff d0 call *%eax 8048472: c9 leave 8048473: c3 ret 08048474 <_Z3fn2v>: { int a; }ST3; void fn2() { 8048474: 55 push %ebp 8048475: 89 e5 mov %esp,%ebp 8048477: 83 ec 18 sub $0x18,%esp printf("fn2\n"); 804847a: c7 04 24 a4 85 04 08 movl $0x80485a4,(%esp) 8048481: e8 16 ff ff ff call 804839c <puts@plt> } 8048486: c9 leave 8048487: c3 ret 08048488 <main>: int main() { 8048488: 55 push %ebp 8048489: 89 e5 mov %esp,%ebp 804848b: 83 e4 f0 and $0xfffffff0,%esp 804848e: 83 ec 20 sub $0x20,%esp int c; int d=0; 8048491: c7 44 24 1c 00 00 00 movl $0x0,0x1c(%esp) 8048498: 00 printf("shint\n"); 8048499: c7 04 24 a8 85 04 08 movl $0x80485a8,(%esp) 80484a0: e8 f7 fe ff ff call 804839c <puts@plt> return 0; 80484a5: b8 00 00 00 00 mov $0x0,%eax } 80484aa: c9 leave 80484ab: c3 ret 080484ac <_Z3fn1v>: void fn1() { 80484ac: 55 push %ebp 80484ad: 89 e5 mov %esp,%ebp 80484af: 83 ec 18 sub $0x18,%esp printf("fn1\n"); 80484b2: c7 04 24 ae 85 04 08 movl $0x80485ae,(%esp) 80484b9: e8 de fe ff ff call 804839c <puts@plt> } 80484be: c9 leave 80484bf: c3 ret 080484c0 <_Z3fn3v>: void fn3() { 80484c0: 55 push %ebp 80484c1: 89 e5 mov %esp,%ebp 80484c3: 83 ec 18 sub $0x18,%esp printf("fn2\n"); 80484c6: c7 04 24 a4 85 04 08 movl $0x80485a4,(%esp) 80484cd: e8 ca fe ff ff call 804839c <puts@plt> } 80484d2: c9 leave 80484d3: c3 ret 80484d4: 90 nop 80484d5: 90 nop 80484d6: 90 nop 80484d7: 90 nop 80484d8: 90 nop 80484d9: 90 nop 80484da: 90 nop 80484db: 90 nop 80484dc: 90 nop 80484dd: 90 nop 80484de: 90 nop 80484df: 90 nop 080484e0 <__libc_csu_fini>: 80484e0: 55 push %ebp 80484e1: 89 e5 mov %esp,%ebp 80484e3: 5d pop %ebp 80484e4: c3 ret 80484e5: 66 66 2e 0f 1f 84 00 nopw %cs:0x0(%eax,%eax,1) 80484ec: 00 00 00 00 080484f0 <__libc_csu_init>: 80484f0: 55 push %ebp 80484f1: 89 e5 mov %esp,%ebp 80484f3: 57 push %edi 80484f4: 56 push %esi 80484f5: 53 push %ebx 80484f6: e8 4f 00 00 00 call 804854a <__i686.get_pc_thunk.bx> 80484fb: 81 c3 0d 13 00 00 add $0x130d,%ebx 8048501: 83 ec 1c sub $0x1c,%esp 8048504: e8 33 fe ff ff call 804833c <_init> 8048509: 8d bb 08 ff ff ff lea -0xf8(%ebx),%edi 804850f: 8d 83 08 ff ff ff lea -0xf8(%ebx),%eax 8048515: 29 c7 sub %eax,%edi 8048517: c1 ff 02 sar $0x2,%edi 804851a: 85 ff test %edi,%edi 804851c: 74 24 je 8048542 <__libc_csu_init+0x52> 804851e: 31 f6 xor %esi,%esi 8048520: 8b 45 10 mov 0x10(%ebp),%eax 8048523: 89 44 24 08 mov %eax,0x8(%esp) 8048527: 8b 45 0c mov 0xc(%ebp),%eax 804852a: 89 44 24 04 mov %eax,0x4(%esp) 804852e: 8b 45 08 mov 0x8(%ebp),%eax 8048531: 89 04 24 mov %eax,(%esp) 8048534: ff 94 b3 08 ff ff ff call *-0xf8(%ebx,%esi,4) 804853b: 83 c6 01 add $0x1,%esi 804853e: 39 fe cmp %edi,%esi 8048540: 72 de jb 8048520 <__libc_csu_init+0x30> 8048542: 83 c4 1c add $0x1c,%esp 8048545: 5b pop %ebx 8048546: 5e pop %esi 8048547: 5f pop %edi 8048548: 5d pop %ebp 8048549: c3 ret 0804854a <__i686.get_pc_thunk.bx>: 804854a: 8b 1c 24 mov (%esp),%ebx 804854d: c3 ret 804854e: 90 nop 804854f: 90 nop 08048550 <__do_global_ctors_aux>: 8048550: 55 push %ebp 8048551: 89 e5 mov %esp,%ebp 8048553: 53 push %ebx 8048554: 8d 64 24 fc lea -0x4(%esp),%esp 8048558: a1 10 97 04 08 mov 0x8049710,%eax 804855d: 83 f8 ff cmp $0xffffffff,%eax 8048560: 74 12 je 8048574 <__do_global_ctors_aux+0x24> 8048562: bb 10 97 04 08 mov $0x8049710,%ebx 8048567: 90 nop 8048568: 8d 5b fc lea -0x4(%ebx),%ebx 804856b: ff d0 call *%eax 804856d: 8b 03 mov (%ebx),%eax 804856f: 83 f8 ff cmp $0xffffffff,%eax 8048572: 75 f4 jne 8048568 <__do_global_ctors_aux+0x18> 8048574: 8d 64 24 04 lea 0x4(%esp),%esp 8048578: 5b pop %ebx 8048579: 5d pop %ebp 804857a: c3 ret 804857b: 90 nop Disassembly of section .fini: 0804857c <_fini>: 804857c: 55 push %ebp 804857d: 89 e5 mov %esp,%ebp 804857f: 53 push %ebx 8048580: 83 ec 04 sub $0x4,%esp 8048583: e8 00 00 00 00 call 8048588 <_fini+0xc> 8048588: 5b pop %ebx 8048589: 81 c3 80 12 00 00 add $0x1280,%ebx 804858f: e8 5c fe ff ff call 80483f0 <__do_global_dtors_aux> 8048594: 59 pop %ecx 8048595: 5b pop %ebx 8048596: c9 leave 8048597: c3 ret----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
댓글 달기