1 / 19

강의 소개 & MinGW & gcc

강의 소개 & MinGW & gcc. 공학기초설계 Youn-Hee Han http://icl.kut.ac.kr. 강의 소개. 강의 목적 C 언어로 문제 해결 훈련 C 프로그래밍 실력 향상 강의 방법 수업시간에 주어지는 2 개의 문제를 C 언어로 개별적으로 풀어보고 Solution 을 설명한다 . 각 문제별 시간할당 개별 해결 시간 : 1 시간 Solution 풀이 : 30 분. 강의 소개. 평가 방법 Homework 로 제출되는 내용에 대하여 다음을 평가 제출유무

wilona
Download Presentation

강의 소개 & MinGW & gcc

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 강의소개 & MinGW & gcc 공학기초설계 Youn-Hee Han http://icl.kut.ac.kr

  2. 강의 소개 • 강의 목적 • C언어로 문제 해결 훈련 • C프로그래밍 실력 향상 • 강의 방법 • 수업시간에 주어지는 2개의 문제를 C언어로 개별적으로 풀어보고 Solution을 설명한다. • 각 문제별 시간할당 • 개별 해결 시간: 1시간 • Solution 풀이: 30분

  3. 강의 소개 • 평가 방법 • Homework로 제출되는내용에 대하여 다음을 평가 • 제출유무 • 제출: 10점, 미제출: 0점 • 완성도 • 완벽완성: 10점, 부분완성: 5점, 해결을 거의 못함: 1점 • 제출시간 • 기한 2일전: 10점 • 기한 1일전: 9점 • 기한: 8점 • 기한초과: 3점 • 실행코드 (exe) & 메모리 사이즈 (상대평가) • 상위 20%: 10점 • 중간 60%: 8점 • 하위 20%: 6점 • 기말고사: 실기 시험 • 평가방법: 절대평가 • 출석: 10%, Homework: 50%, 기말 고사: 40%

  4. MinGW • MinGW (Minimalist GNU for Windows) • http://www.mingw.org/ • A collection of freely available and freely distributable Windows specific header files and import libraries, augmenting the GNU Compiler Collection, (GCC), and its associated tools, (GNU binutils). • MinGW provides a complete Open Source programming tool set which is suitable for the development of native Windows programs that do not depend on any 3rd-party C runtime DLLs. • 기본 설치면 C언어를 위한 gcc가 설치 됨 • 다음과 같은 추가 옵션 선택 가능 • gcc-g++ for C++ • gcc-objc for Objective C • gcc-g77 for Fortran 77 • gcc-java for Java • gcc-ada for Ada • mingw-gdb for debugger • mingw32-make for make • mingw-utils for MinGW Utilities • c:\MinWG 폴더를 path 환경변수에 할당

  5. gcc • gcc • ‘GNU C++ Compiler’의 약자로 C나 C++(이하 C)로 만든 소스파일을 Compile 및 linking 하여 목적, 실행 파일을 만드는 프로그램 • gcc 특성 • gcc는 Windows OS에서 많이 활용하는 Visual C/C++과같은 Visual 환경을 제공하지 않음 • gcc 는 수동적인 방식임 • 상용 유닉스에 달려오는 AT&T 스타일, BSD 스타일의 C 언어 문법은 물론 ANSI C 를 기본으로 하여 모든 문법을 소화해낼 수 있음 • 특유의 문법도 가지고 있으며. 구식 컴파일러, 구식 문법도 지원하고 있음 • 상용 유닉스에는 cc 가 지원되지만 gcc 를 설치하여 사용하는 경우가 많음

  6. gcc 사용 • 적절한 Editor로 C 프로그램 작성 • 파일명: test.c int a,b,c; int main() { scanf("%d %d %d", &a, &b, &c); printf("%d", a+b+c); exit(0); }

  7. gcc 사용예 • MinGW에서 제공하는 gcc 사용 예 • gcc test.c • a.exe • gcc –o 1.exe test.c • 1.exe • gcc –c test.c • test.o • gcc –o 2.exe test.o • 2.exe 컴파일 *.c(소스파일) -------> *.o(목적파일) 링크 *.o(목적파일) -------> a.out(실행파일)

  8. Program, Process, Memory • Program & Process • process is a running program • Process & Memory • Without memory for storing data, it's impossible for a program to get any work done. • Process leads to the use of dynamically allocated memory -- memory allocated at runtime instead of at compile time. • A process has five conceptually different areas of memory allocated to it: • Code (Text) • Initialized Data • Zero(Default)-initialized Data • Heap • Stack

  9. Program, Process, Memory • Memory and “size” program bss data total (dec & hex) text BSS is an acronym for "Block Started by Symbol," a mnemonic from the IBM 7094 assembler

  10. Program, Process, Memory • Five Memory Blocks • Code (Text) • The area where the executable instructions reside. • Initialized Data • The area where statically allocated and global data that are initialized to non-default values • Zero(Default)-initialized Data • The area where statically allocated and global data that are initialized to zero by default • Heap • The area where dynamic memory (obtained by malloc() and friends) resides • Stack • The area where local variables are allocated. • Local variables are all variables declared inside the opening left brace of a function body (or other left brace) that aren't defined as static. • function parameters are also placed on the stack

  11. Program, Process, Memory • gcc, size, strip • The strip program removes the symbols from the object file. • This can save significant disk space for a large program, at the cost of making it impossible to debug • Even after removing the symbols, the program file size is invariable $ gcc -o ch03-memaddr ch03-memaddr.c Compile the program $ ls -l ch03-memaddr Show program size -rwxr-xr-x 1 arnold devel 12320 Nov 24 16:45 ch03-memaddr $ size ch03-memaddr Show memory sizes text data bss dec hex filename 1458 276 8 1742 6ce ch03-memaddr $ strip ch03-memaddr Remove symbols $ ls -l ch03-memaddr Show program size again -rwxr-xr-x 1 arnold devel 3480 Nov 24 16:45 ch03-memaddr $ size ch03-memaddr Component sizes haven't changed text data bss dec hex filename 1458 276 8 1742 6ce ch03-memaddr

  12. Appendix

  13. 1. 프로세스의 메모리 배치 • 프로세스 이미지 • 프로세스는 일정한 메모리를 배정 받아 사용 • 프로그램 실행에 필요한 어셈블러 코드, 변수가 저장 • 원칙적으로 한 프로세스는 다른 프로세스의 메모리 영역에 접근 불가 • C 프로그램과 이미지의 내용 #include <stdio.h> #include <stdlib.h> extern char **environ; //extern 변수 int init_global_var = 3; //초기화된 global 변수 int unint_global_var; //초기화되지 않은 global 변수 int main(int argc, char **argv) { int auto_var; //automatic 변수 (local variable) static int static_var; //static 변수 register int reg_var; //register 변수 char *auto_ptr; //automatic 변수 (local variable) auto_ptr = malloc(10); return 0; }

  14. 1. 프로세스의 메모리 배치 • 프로세스의 메모리 영역과 저장되는 변수 종류 하위 메모리 상위 메모리

  15. 1. 프로세스의 메모리 배치 #include <stdio.h> void test(void) { static int s_count=0; int a_count=0; s_count++; a_count++; printf("static count=%d\tauto count=%d\n", s_count, a_count); } void main(void) { int i; for(i=0; i<5; i++) test(); }

  16. 2. 스택과 힙 • 스택 (Stack) • 현재 호출되어 실행중인 함수의 코드와 환경 정보를 저장 • 예) • main()에서 printf()를 호출하였다면 main()이 차지하는 영역 위에 printf()를 처리하기 위한 메모리가 할당되고 printf()가 수행 • print()가 리턴되면 printf()와 관련된 영역은 삭제되고 프로세서의 수행은 main()으로 돌아감 • 함수 내부에서 임시로 사용되는 automatic 변수는 스택 영역에 할당 • automatic 변수 – 자동으로 생성되었다가 자동으로 없어지는 변수 • 힙 (Heap) • 스택은 영역 사용하던 메모리가 함수의 종료와 함께 사라짐 • 이 문제를 해결하기 위하여 리턴되어도 사라지지 않도록 한 영역이 힙 • malloc() 함수를 사용한 역영은 힙에 저장

  17. 2. 스택과 힙 int main() { char *prt; ptr = func(); } char *func() { char arr[10]; return arr; } int main() { char *prt; ptr = func(); // ptr 사용 free(ptr); // ptr 사용 종료 } char *func() { char *arr; arr = malloc(10); return arr; }

  18. 3. 활성화 레코드 (Activation Record) • 메인함수 호출에 따른 활성화 레코드 • int a;                  전역 변수 void main( ) { int b; char *s;       지역변수(스택) s = malloc(10);      10 바이트짜리 동적변수(힙) b = fcn(5); free (s); }

  19. 4. 활성화 레코드 (Activation Record) • 일반 함수 호출에 따른 활성화 레코드 • int fcn(int p)  {  파라미터(스택) int b = 2;     b = b + p; return (b); }

More Related