바인딩, 메모리관리 SANGJI University Kwangman Ko 속성 (attributes) o 속성 (attributes) ~ 특성 (properties) 들의집합 ~ 변수의위치 (location) 값이저장될수있는공간,

Size: px
Start display at page:

Download "바인딩, 메모리관리 SANGJI University Kwangman Ko 속성 (attributes) o 속성 (attributes) ~ 특성 (properties) 들의집합 ~ 변수의위치 (location) 값이저장될수있는공간,"

Transcription

1 바인딩, 메모리관리 SANGJI University Kwangman Ko () 속성 (attributes) o 속성 (attributes) ~ 특성 (properties) 들의집합 ~ 변수의위치 (location) 값이저장될수있는공간, 컴퓨터메모리주소 ~ 값 (value) 저장가능한대상 ~ 타입 (data type) 저장되는값의범위 (range) 결정 ~ 명칭 (= 식별자 = identifiers) ~ 영역 (scope) ~ 존속기간 (life-time) ~ 2 프로그래밍언어론 (2006, 상지대학교 ) 1

2 o const int n = 5 ; ~ Q) 명칭 n 의의미를결정하는것? ~ A) 속성 o double func ( int n ) { ~ 매개변수수, 매개변수이름, 매개변수자료형 ~ 반환자료형 (return type), double ~ 함수호출시실행되는코드부분 o int *y; (in C), y=new int; (in C++) ~ 의미? ~ 기억공간의구조를그림의표현? 3 바인딩 (Binding)? o 정의 ~ 어떠한대상 ( 변수와같은 ) 과성질 ( 변수의값과같은 ) 의연결 ~ 이름에어떤속성을연결하는과정 ~ 속성과개체의결합, 연산과기호의결합, ~ 프로그램의기본단위에이단위가택할수있는여러속성중에서일부를선정하여결정하는행위 4 프로그래밍언어론 (2006, 상지대학교 ) 2

3 o 종류 ~ 정적바인딩 (static binding) 이름과대상의연결작업이실행시간이전에일어나는바인딩. ~ 동적바인딩 (dynamic binding) 이름과대상의연결작업이실행시간에일어나는바인딩 o 바인딩이발생되는시점? 5 o Example of Binding // C++ example int x, *y; x = 2; y = new int(3); x y Type: integer Value: 2 Type: integer pointer Value: 3 6 프로그래밍언어론 (2006, 상지대학교 ) 3

4 바인딩시간 (binding time) o 바인딩시간 (binding time) ~ 실제로바인딩이일어나는시간 o 바인딩시간의분류 (categories) ~ 정적바인딩 (static binding) 실행시간이전에일어나는바인딩 ~ 동적바인딩 (dynamic binding) 실행시간에일어나는바인딩 7 o Further Refined Binding Time ~ Language definition time ~ Language implementation time ~ Program translation time ~ Link time, Load time ~ Execution time (run time) 8 프로그래밍언어론 (2006, 상지대학교 ) 4

5 o 수식 (expression) 의값 ~ execution time if it contains variables ~ translation time if it is a constant expression o 명칭 (identifier) 에대한자료형 ~ translation time in a compilation system C, C++, C#, Java, ~ execution time in an interpreter LISP, APL, SNOBOL4, 9 o 정수 (integer) ~ language definition time, 정수의부분집합 ~ language implementation time, 최대및최소범위 o 변수의위치 (location) ~ load time for static variables (static in C) ~ execution time for dynamic variables (auto in C) 10 프로그래밍언어론 (2006, 상지대학교 ) 5

6 구문문제 o 이름결정규칙 ~ 어휘규칙 (Lexical rules) 에의하여이름형태가결정. ~ 예 ) C/Clite 언어등 문자로시작, o 대소문자구분 (Case sensitivity) ~ C언어류 : yes ~ 초기의언어들 : no ~ PHP: 부분적으로구분또는비구분 11 o 예약어 (reserved words), 지정어 (keywords) ~ 특별한의미를가지는명칭 ~ 일반적인명칭 ( 변수이름, 함수이름등 ) 으로사용할수없음 o 예약어 ~ 미리정의된식별자의예 : 라이브러리함수명 o 명칭의재정의, 예약어 ~ 해로울까? Or 해롭지않을까? ~ 예 ) C : typedef int Integer 12 프로그래밍언어론 (2006, 상지대학교 ) 6

7 Symbol Table and Environment o 심볼테이블 (symbol table) ~ 번역 / 실행되는동안명칭에적절한의미정보부여 / 관리 ~ 바인딩정보를저장하고있는언어번역기의자료구조. ~ Mathematically, a function SymbolTable: Names Attributes 13 o 컴파일시스템 ~ 다양한속성이다양한함수에의해유지 심벌테이블 : Names (Some) 정적속성 환경 : Names 메모리위치 (locations) 메모리 : Locations Values o 해석 (interpretation) 시스템 ~ 정적및동적속성이모두실행시간에계산 ~ 심벌테이블과환경이조합 환경 : Names Attributes 14 프로그래밍언어론 (2006, 상지대학교 ) 7

8 선언 (declarations) o 선언 : 바인딩을구성하는중요한방법 ~ 묵시적 (implicit) 바인딩 ~ 명시적 (explicit) 바인딩, 명확한지정 ~ Example( in C ) int x; the type binding is an explicit binding the location binding is an implicit binding 초기값 15 o 묵시적선언 ~ 명칭사용규칙 (naming convention) ~ FORTRAN example the variable whose name starts with I, J, K, L, M, or N is implicitly an integer ~ BASIC example ~ the trailing % of variable means an integer, $ means a string 16 프로그래밍언어론 (2006, 상지대학교 ) 8

9 Different Terms for Declarations o 정의 (definition) ~ a declaration that binds all potential attributes ~ 모든잠재적인속성을바이딩하는선언 o 선언 (declaration) ~ a declaration that binds only a part of attributes ~ 속성일부분만을바인딩하는선언 17 o 함수선언 ( in C ) double f(int x) ; ~ 원형 (prototype) 함수 f 의데이터타입 ( 매개변수타입, 반환형 ) 만기술 구현몸체는기술하지않음. binds only the type (the interface) of the function 18 프로그래밍언어론 (2006, 상지대학교 ) 9

10 블록과지역성 o 블록 (block) ~ 선언과문장들의연속으로구성된언어구조 ~ 할당의단위 (unit of allocations) o 선언과참조의지역성 (locality) ~ 지역적 (local): 명칭에대한선언과참조가동일블록으로제한 ~ 비지역적 (non-local) the declaration of a name is not in the block which contains the reference for the name 19 void p (void) { double r, z; /* p 블록 */ { int x, y; /* 내포된블록 */ x = 2; y = 0; x += 1; 20 프로그래밍언어론 (2006, 상지대학교 ) 10

11 블록구조화 (Block-Structured) o 블록구조화프로그램 ~ 중첩될수있는여러개의블록으로구성된프로그램 ~ Algol60에서시도 ~ 후손언어에서블록구조를다양한방법으로제공 ~ 순차블록 : Pascal ~ 비순차블록 : Ada, C -- Ada example declare x: integer; begin end (* Pascal example *) program ex; var x: integer begin end 21 o 구조화자료형 (Structured Data Type) ~ a type declaration which contains declarations 내포된선언 (nested declaration) ~ 구조체 in C, 클래스 in C++, Java, Smalltalk o 모듈 (Module) or 패키지 (Package) ~ a collection of declarations ~ the collection itself is not a declaration Ada: package and task Java: package ML and Haskell: module C++: namespace 22 프로그래밍언어론 (2006, 상지대학교 ) 11

12 영역, 스코프 (Scope) o 바인딩의영역 (Scope of a Binding) ~ 바인딩이유지되는범위, 위치가중요정보 ~ 선언에의해결정된바인딩이동일영역유지, 선언의영역 o 이름의영역 (Scope of a Name) ~ 동일이름이중복되어선언될수있음 => 위험 ~ these different declarations of the same name should be differentiated 23 영역규칙 (Scope Rules) o 정적 (static) 영역규칙 ~ 블록영역이선언을포함하고있는블록내부로제한 ~ 대부분의블록구조프로그램은정적영역규칙을따름 o 동적 (dynamic) 영역규칙 ~ 바인딩영역이실행경로 (path) 에따라결정 ~ 심볼테이블이동적으로정보를유지 24 프로그래밍언어론 (2006, 상지대학교 ) 12

13 Lexical Scope Example (C) int x; void p(void) { char y;... /* p */ y In C, the declaration before use rule apply. void q(void) { double z;... /* q */ z p x q main() { int w[10];... w main 25 Scope Holes o 영역구멍 (scope hole)? ~ 명칭의지역선언은동일한이름의이전 (prior) 선언을마스크 (mask) 함. ~ 마스크된선언은해당블록전체에대해영역구멍을갖음. o 가시성 (visibility) ~ 선언된명칭의바인딩이적용되는부분 ( 영역구멍배제 ) o 영역 (scope) ~ 바인딩이존재하며가시성이숨겨진영역포함 ( 영역구멍포함 ) 26 프로그래밍언어론 (2006, 상지대학교 ) 13

14 int x; void p(void) { char x; x = a ; /* char x 에배정 */ /* p */ main() { x = 2; /* 전역 x 에배정 */ Scope Resolution Operator // C++ example int x; void p(void) { char x; x = 'a'; // local x ::x = 42; // global x... /* p */ main() { x = 2;... // global x o The global integer variable x has a scope hole in the body of p. o In C, the global x cannot be referenced in p. o In C++, the global x can be referenced in p using a scope resolution operator ::. o Ada also has a scope resolution operator.. 28 프로그래밍언어론 (2006, 상지대학교 ) 14

15 File Scope in C o File Scope ~ In C, a global name can be turned into a file scope name by attaching the keyword static. ~ A file scope name can only be referenced in that file. File 1 extern int x;... x... int x;... x... File 2 File 3 static int x;... x Java Scope Example public class Scope { public static void f() { System.out.println(x); public static void main(string[] args) { int x = 3; f(); public static int x = 2; 30 프로그래밍언어론 (2006, 상지대학교 ) 15

16 o 클래스선언 ( in Java ) ~ 선언의영역을클래스전체 o 출력되는값? ~ the above code prints 2. ~ under dynamic scope rule, the code would print 동적스코프 (dynamic scope) o 동적스코드의단점 (disadvantages) ~ 선언의영역이정적으로결정되지않음. ~ 선언의영역을결정하기위해 Hand-simulation 수행. ~ 명칭의자료형이정적으로결정될수없음. ~ 정적자료형검사 (static type-checking) 불가능 o Next chapters 32 프로그래밍언어론 (2006, 상지대학교 ) 16

17 Symbol Table Maintenance o 심볼테이블이란? ~ 명칭에연관된모든속성을저장하는공간 ~ 효율적인삽입, 검색, 삭제연산방법 ~ 효율적접근과유지를위한자료구조 해쉬테이블, 트리, 연결리스트, o 정적영역 (lexically scoped languages) ~ 심볼테이블이스택과같은방법으로운영 블록진입시모든선언을처리하여대응하는바인딩추가 블록진출시선언에의해제공된모든바인딩제거, 복구 ~ 심볼테이블운영이실행경로 ( 순서 ) 와무관. 33 ST under Lexical Scope int x; char y; void p(void) { double x;... { /* block b */ int y[10]; void q(void) { int y;... main() { char x;... x x x y y y p p p q q main main double local double local double int into p to local global global int to p global int char local global char to main int[10] global char local char b global to q global char global void function void void function function void function void function void function void function void function int function int function int global int global int global int global char global 34 프로그래밍언어론 (2006, 상지대학교 ) 17

18 ST under Dynamic Scope #include <stdio.h> int x = 1; char y = 'a'; x double=2.5 char='b' int=1 local global local to to main p char int=1 global void p(void) { double x = 2.5; printf("%c\n",y) { /* block b */ int y[10]; void q(void) { int y = 42; printf("%d\n",x); p(); main() { char x = 'b'; q(); return 0; y p q main Output int=42 char='a' char='a' local global to q global void function void function int function ASCII value of 'b' 98 * ASCII 42 = 'b' 35 o 동적영역 (dynamically scoped languages) ~ 가장바깥쪽의명칭의바인딩이구성. ~ 바인딩이프로그램실행경로에따라유지 비지역변수참조에대해적용된실행순서추적방법? 비지역변수의참조가실행이전에예측할수없음. 36 프로그래밍언어론 (2006, 상지대학교 ) 18

19 다중적재 (overloading) o 다중적재? ~ 서로다른엔티티에대해명칭을재사용 ~ 같은이름을사용하여프로그램의다른대상을참조 ~ 3+4 vs 어셈블리언어 : ADDI, ADDF 번역기는피연산자의자료형을참고 ~ 연산자중복 (operator overloading) C++ ~ 함수중복 (function overloading) C++, Java 37 o the operator + is overloaded ~ integer addition (say, ADDI) ~ floating point number addition (say, ADDF) o How about mixed-type expression? ~ ~ C/C++ : promotion (implicit type conversion). ~ Ada : Error. o Signature ~ 반환형, 매개변수개수, 매개변수자료형 38 프로그래밍언어론 (2006, 상지대학교 ) 19

20 int max(int x, int y) // max #1 { return x > y? x : y; double max(double x, double y) // max #2 { return x > y? x : y; int max(int x, int y, int z) // max #3 { return x > y? (x > z? x : z) : (y > z? y : z); o Name resolution ~ max(2,3) // calls max #1 ~ max(2.1,3.2) // calls max #2 ~ max(1,3,2) // calls max #3 39 Overload Resolution Issues o 묵시적자료형변환은모호한 (ambiguous) 호출 ~ max(2.1, 3) // max??? ~ C++: too many candidates (max #1 or max #2) ~ Ada: no candidates ~ Java: 묵시적자료형변환은정보손실이없는경우로제한 o 다중적재에서반환형의고려여부? ~ 함수의반환형을함수호출정보로포함할것인가? ~ C++, Java: not included ~ Ada: included 40 프로그래밍언어론 (2006, 상지대학교 ) 20

21 Function Overloading in Ada procedure overload is function max(x: integer; y: integer) -- max #1 return integer is begin... end max; function max(x: integer; y: integer) -- max #2 return float is begin... end max; a: integer; b: float; begin -- max_test a := max(2,3); -- call to max # 1 b := max(2,3); -- call to max # 2 end overload; In Ada, the return type is included in the calling context. 41 Operator Overloading in C++ #include <iostream> using namespace std; typedef struct { int i; double d; IntDouble; bool operator < (IntDouble x, IntDouble y) { return x.i < y.i && x.d < y.d; IntDouble operator + (IntDouble x, IntDouble y) { IntDouble z; z.i = x.i + y.i; z.d = x.d + y.d; return z; int main() { IntDouble x = {1, 2.1, y = {5, 3.4; if (x < y) x = x + y; else y = x + y; cout << x.i << " " << x.d << endl; return 0; 42 프로그래밍언어론 (2006, 상지대학교 ) 21

22 Operator Overloading in Ada procedure opover is type IntDouble is record i: Integer; d: Float; end record; function "<" (x,y: IntDouble) return Boolean is... function "+" (x,y: IntDouble) return IntDouble is... x, y: IntDouble; begin x := (1,2.1); y := (5,3.4); if (x < y) then x := x + y; else y := x + y; end if; put(x.i); put(" "); put(x.d); new_line; end opover; 43 명칭의재사용 o Reusing names for different kinds of entities ~ Separate name space for each kind is needed. ~ These kinds of reusing is not an overloading. C example typedef struct A A; struct A { int data; A * next; ; structure tag name type name Java example class A { A A(A A) { A: for(;;) Which is which? class name method name parameter name label name { if (A.A(A) == A) break A; return A; 44 프로그래밍언어론 (2006, 상지대학교 ) 22

23 실행환경 (Environment) o 환경 ~ 명칭과위치 (location) 를연결시키는것. o 환경결정시간 ~ 정적환경 : FORTRAN ~ 동적환경 : LISP ~ 혼합 (mixture) : most Algol-style languages o 모든명칭이환경에연결되는것은아님. ~ 상수 ~ Const int MAX = 10; 45 o 변수에대한기억장소할당시간 ~ 전역변수 (global variable) ~ 정적기억장소할당 ~ 로딩시간 (load time) 에기억장소할당 ~ 지역변수 ~ 동적기억장소할당 ~ 제어가도달할때선언된변수에대한기억장소할당 46 프로그래밍언어론 (2006, 상지대학교 ) 23

24 전형적인실행환경의구조 o 정적영역 (static area) ~ static allocation o 스택영역 (stack) ~ LIFO-style dynamic allocation ~ 정적기억장소할당 o 힙영역 (heap) ~ on-demand dynamic allocation ~ 동적기억장소할당 47 활성화레코드 (Activation Record) o 활성화 (Activation) ~ 부프로그램호출을호출하면? ~ 각부프로그램호출 (invocation or activation) 에대해각부프로그램에대한환경에구축되어야함. o 활성화레코드 (Activation Record; AR) ~ 부프로그램호출에대해할당되는메모리공간 ~ subprogram environment + bookkeeping information 48 프로그래밍언어론 (2006, 상지대학교 ) 24

25 o 실행시간스택 (Run-Time Stack) ~ 블록의진입과진출이 LIFO 방식으로운용 ~ 프로시쥬어호출과반환이 LIFO 방식으로운용 ~ 활성화레코드들이실행시간스택에저장. 49 Run-Time Stack Manipulation A: { int x; point 1 char y; B: { double x; int a; /* end B */ C: { char y; int b; D: { int x; double y; /* end D */ /* end C */ /* end A */ 50 프로그래밍언어론 (2006, 상지대학교 ) 25

26 Run-Time Stack Manipulation A: { int x; char y; B: { double x; int a; /* end B */ C: { char y; int b; D: { int x; double y; /* end D */ /* end C */ /* end A */ point 2 51 Run-Time Stack Manipulation A: { int x; char y; B: { double x; int a; /* end B */ C: { char y; int b; D: { int x; double y; /* end D */ /* end C */ /* end A */ point 3 52 프로그래밍언어론 (2006, 상지대학교 ) 26

27 Run-Time Stack Manipulation point 4 A: { int x; char y; B: { double x; int a; /* end B */ C: { char y; int b; D: { int x; double y; /* end D */ /* end C */ /* end A */ 53 Run-Time Stack Manipulation point 5 A: { int x; char y; B: { double x; int a; /* end B */ C: { char y; int b; D: { int x; double y; /* end D */ /* end C */ /* end A */ 54 프로그래밍언어론 (2006, 상지대학교 ) 27

28 힙 (heap) 메모리영역관리 o 힙메모리 (Free Store) 할당 ~ 객체 (objects) 의할당에대해지원되는메모리구역 (pool) 환경에서선언처리의결과로생기는할당된기억장소구역 ~ 동적메모리공간 o 힙메모리반환 (deallocation) ~ 사용을마친힙메모리구역에대한반환함수또는연산자사용 free() in C, delete in C++, Ada. ~ 자동반환 (automatic deallocation) garbage collector 사용 안전하기는하지만속도저하의문제점, in Java 55 Pointer and Dereferencing o 포인터 ~ 다른객체의위치 (= 주소 ) 를값으로갖는객체. ~ int *x = NULL; x는할당된객체를가리키기위해수동으로객체할당 x = ( int * ) malloc( sizeof( int ) ) ; o 참조인출 (dereferencing) ~ 주소 (pointer value) 를통한객체참조. 56 프로그래밍언어론 (2006, 상지대학교 ) 28

29 /* C example */ int *x; // pointer declaration x = (int*)malloc(sizeof(int)); // memory allocation *x = 5; // dereferencing printf( %d\n, *x); free(x); // deallocation /* C++ example */ int* x = new int; *x = 2; cout << *x << endl; delete x; /* Java example */ Integer x = new Integer(2); System.out.println(x); // delete 연산이필요없음. 57 생명시간 (Lifetime) o 객체 (storable object) ~ a chunk of memory cells ~ 환경에서할당되는기억장소구역 (area of storage) o 객체의생명시간 (lifetime or extent) ~ 환경에서기억장소가할당되어소멸까지의소요시간 58 프로그래밍언어론 (2006, 상지대학교 ) 29

30 o 생명시간 (lifetime) vs. 영역 (scope) ~ 변수에대한생명시간과영역은밀접한관련은있지만동일하지않음. ~ local static variables in C/C++ 영역 : local, global 생명시간 : static, dynamic 59 Local Static Variable Example (C) int p(void) { static int p_count = 0; p_count += 1; return p_count; main() { int i; for (i = 0; i < 10; i++) { if ( p() % 3 ) printf("%d\n", p() ); return 0; 60 프로그래밍언어론 (2006, 상지대학교 ) 30

31 변수와상수 o 변수 (variable) ~ 실행시간동안변환되는값을저장하는객체 (= 기억공간 ) ~ 명칭이실제메모리주소로변환 ( 언제 : ). o 상수 (constants) ~ 생명시간동안변하지않는객체의값 ~ an object whose value does not change for its lifetime o 리터럴 (literals) ~ 명칭에의해값이명확하게정해지는객체 61 Diagrams for Variables o Schematic Representation o Box-Circle Diagram 62 프로그래밍언어론 (2006, 상지대학교 ) 31

32 L-value and R-value ol-value and R-value ~ l-value (LHS value): the location ~ r-value (RHS value): the value stored ~ X=10( ), x=y( ), 100 = z ( ). 63 배정 (assignment) o 배정 ~ 변수의값을변경하는가장기본적인방법 ~ variable assingmentopertor expression ( 중위법 ) ~ 값의복사 (value-copying) 에의한배정 ~ 포인터에의한배정 (pointer semantics) 공유에의한배정 (shallow copying) 복제에의한배정 (deep copying) 복제 (cloning) 객체를메모리에정확히복사 64 프로그래밍언어론 (2006, 상지대학교 ) 32

33 Assignment by Value-Copying o 변수의값이복사. ~ x = y 65 공유 (sharing) 에의한배정 o 변수의위치 (location) 가복사. ~ x = y ~ 변수 y의위치가 x에바인딩. 66 프로그래밍언어론 (2006, 상지대학교 ) 33

34 복제 (cloning) 에의한배정 o 변수의값 (value) 과위치 (location) 가복제. ~ x = y ~ 새로운위치를할당하여 y의값을복사 ~ 새로할당된위치를 x에바인딩 67 Java Example o Java supports ~ 공유에의한배정 assignment of object variables ~ 값-복사에의한배정 assignment of simple data ~ 복제에의한배정 메소드복제 (method clone.) 68 프로그래밍언어론 (2006, 상지대학교 ) 34

35 o A closer view of object assignment in Java ~ x = y 69 상수 (constant) Semantics o 상수다이어그램 o 상수의의미 (semantics) ~ 바인딩이결정되면실행중변화가없음. ~ 상수의위치는참조되지않음. 값만유지하고위치속성을갖지않음. 70 프로그래밍언어론 (2006, 상지대학교 ) 35

36 상수의분류 o 리터널 and Named Constants ~ literals: 값을표현하는명칭 ~ named constants: 값의의미에대한명칭 o Named Constants 분류 ~ 정적상수 ( = 상수 ) 실행이전에값이계산될수있는상수 컴파일시간 (compile-time) 정적상수, 적재시간 (load-time) 정적상수 ~ 동적상수 실행하는동안에만값이계산되는상수 71 상수초기화 o C ~ the initial value of a static constant (or a static variable) should be computed from literals only o C++ ~ the above restriction is removed #include <stdio.h> #include <time.h> const int a = 2; const int b = 27+2*2; /* legal in C */ const int c = (int) time(0); /* illegal C code! */ int b = 27+a*a; /* also illegal in C */ 72 프로그래밍언어론 (2006, 상지대학교 ) 36

37 별칭 (Aliases) o 별칭 (aliases) ~ 동일객체에대해동시에두개이상의명칭을접근 ~ 프로그램판독성저하 ~ 부작용 (harmful side effects) 발생 o 부작용 (side effect) ~ 문장의실행이후에변수의값이변경되는것. o 잠정적으로해로운부작용 ~ 부작용을작성된문장을통해서는결정하기어려움 ~ 실행되는문장의앞부분을참고해야알수있음. 73 An Example of Harmful Aliases main() { int *x, *y; x = (int *) malloc(sizeof(int)); *x = 1; y = x; /* *x and *y now aliases */ *y = 2; printf("%d\n",*x); return 0; 74 프로그래밍언어론 (2006, 상지대학교 ) 37

38 별칭의발생요인? o 별칭의발생요인? ~ 포인터배정문 (pointer assignment) ~ 참조에의한매개변수전달 (call-by-reference parameters) ~ 공유에의한배정 (assignment by sharing) class ArrTest { public static void main(string[] args) { int[] x = { 1, 2, 3; int[] y = x; x[0] = 42; System.out.println( y[0] ); // int[] y = (int[]) x.clone(); 75 허상참조 (dangling references) o 허상참조 ~ 할당된기억장소반환, 접근경로 (= 포인터 ) 존재. ~ 객체에대해환경에서수명종료, 접근경로존재 ~ Dangerous! o 허상참조를만드는요인? ~ pointer assignment and explicit deallocation ~ pointer assignment and implicit deallocation by block exit by function exit 76 프로그래밍언어론 (2006, 상지대학교 ) 38

39 Example of Dangling References main(){ int *x, *y; x = (int *) malloc(sizeof(int)); *x = 1; y = x; /* *x and *y now aliases */ free(x); /* *y now a dangling reference */ printf("%d\n",*y); /* illegal reference */ return 0; 77 쓰레기 (Garbage) o Garbage (Dangling Objects) ~ 할당된기억장소는존재하지만접근경로가없음. ~ 할당된기억장소가너무늦게반환 ~ 메모리낭비발생, but 해롭지는않음. o 쓰레기는만드는요인? ~ 명확한 (explicit) 기억장소할당, 접근경로분실 Assignment deallocation of the access point 78 프로그래밍언어론 (2006, 상지대학교 ) 39

40 An Example of Garbage main() { int *x; x = (int *) malloc(sizeof(int)); x = 1; /* OOPS! */... return 0; 79 Garbage Collection o 언어시스템 ~ automatically reclaims garbage. o 함수언어, 객체지향언어 ~ using garbage collectors. o See you in Memory management section!! 80 프로그래밍언어론 (2006, 상지대학교 ) 40

Ch.1 Introduction

Ch.1 Introduction 바인딩, 메모리관리 SANGJI University Kwangman Ko () 속성 (attributes) 속성 (attributes) ~ 특성 (properties) 들의집합 ~ 변수의위치 (location) 값이저장될수있는공간, 컴퓨터메모리주소 ~ 값 (value) 저장가능한대상 ~ 타입 (data type) 저장되는값의범위 (range) 결정 ~ 명칭

More information

제4장 기본 의미구조 (Basic Semantics)

제4장  기본 의미구조 (Basic Semantics) 제 4 장블록및유효범위 Reading Chap. 5 숙대창병모 1 4.1 변수선언및유효범위 숙대창병모 2 변수선언과유효범위 변수선언 Declaration before Use! 대부분의언어에서변수는사용전에먼저선언해야한다. 변수의유효범위 (scope) 선언된변수가유효한 ( 사용될수있는 ) 프로그램내의범위 / 영역 변수이름뿐아니라함수등다른이름도생각해야한다. 정적유효범위

More information

C# Programming Guide - Types

C# Programming Guide - Types C# Programming Guide - Types 최도경 lifeisforu@wemade.com 이문서는 MSDN 의 Types 를요약하고보충한것입니다. http://msdn.microsoft.com/enus/library/ms173104(v=vs.100).aspx Types, Variables, and Values C# 은 type 에민감한언어이다. 모든

More information

슬라이드 1

슬라이드 1 -Part3- 제 4 장동적메모리할당과가변인 자 학습목차 4.1 동적메모리할당 4.1 동적메모리할당 4.1 동적메모리할당 배울내용 1 프로세스의메모리공간 2 동적메모리할당의필요성 4.1 동적메모리할당 (1/6) 프로세스의메모리구조 코드영역 : 프로그램실행코드, 함수들이저장되는영역 스택영역 : 매개변수, 지역변수, 중괄호 ( 블록 ) 내부에정의된변수들이저장되는영역

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 2... ( ). ( ). @ vs. logic data method variable behavior attribute method field Flow (Type), ( ) member @ () : C program Method A ( ) Method B ( ) Method C () program : Java, C++, C# data @ Program

More information

PowerPoint Presentation

PowerPoint Presentation Class - Property Jo, Heeseung 목차 section 1 클래스의일반구조 section 2 클래스선언 section 3 객체의생성 section 4 멤버변수 4-1 객체변수 4-2 클래스변수 4-3 종단 (final) 변수 4-4 멤버변수접근방법 section 5 멤버변수접근한정자 5-1 public 5-2 private 5-3 한정자없음

More information

chap10.PDF

chap10.PDF 10 C++ Hello!! C C C++ C++ C++ 2 C++ 1980 Bell Bjarne Stroustrup C++ C C++ C, C++ C C 3 C C++ (prototype) (type checking) C C++ : C++ 4 C C++ (prototype) (type checking) [ 10-1] #include extern

More information

Microsoft PowerPoint - additional01.ppt [호환 모드]

Microsoft PowerPoint - additional01.ppt [호환 모드] 1.C 기반의 C++ part 1 함수 오버로딩 (overloading) 디폴트매개변수 (default parameter) 인-라인함수 (in-line function) 이름공간 (namespace) Jong Hyuk Park 함수 Jong Hyuk Park 함수오버로딩 (overloading) 함수오버로딩 (function overloading) C++ 언어에서는같은이름을가진여러개의함수를정의가능

More information

1

1 1 1....6 1.1...6 2. Java Architecture...7 2.1 2SDK(Software Development Kit)...8 2.2 JRE(Java Runtime Environment)...9 2.3 (Java Virtual Machine, JVM)...10 2.4 JVM...11 2.5 (runtime)jvm...12 2.5.1 2.5.2

More information

Microsoft PowerPoint - Chapter_04.pptx

Microsoft PowerPoint - Chapter_04.pptx 프로그래밍 1 1 Chapter 4. Constant and Basic Data Types April, 2016 Dept. of software Dankook University http://embedded.dankook.ac.kr/~baeksj 이장의강의목표 2 기본자료형문자표현방식과문자자료형상수자료형변환 기본자료형 (1/8) 3 변수 (Variables)

More information

JVM 메모리구조

JVM 메모리구조 조명이정도면괜찮조! 주제 JVM 메모리구조 설미라자료조사, 자료작성, PPT 작성, 보고서작성. 발표. 조장. 최지성자료조사, 자료작성, PPT 작성, 보고서작성. 발표. 조원 이용열자료조사, 자료작성, PPT 작성, 보고서작성. 이윤경 자료조사, 자료작성, PPT작성, 보고서작성. 이수은 자료조사, 자료작성, PPT작성, 보고서작성. 발표일 2013. 05.

More information

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt 변수와상수 1 변수란무엇인가? 변수 : 정보 (data) 를저장하는컴퓨터내의특정위치 ( 임시저장공간 ) 메모리, register 메모리주소 101 번지 102 번지 변수의크기에따라 주로 byte 단위 메모리 2 기본적인변수형및변수의크기 변수의크기 해당컴퓨터에서는항상일정 컴퓨터마다다를수있음 short

More information

Microsoft PowerPoint - [2009] 02.pptx

Microsoft PowerPoint - [2009] 02.pptx 원시데이터유형과연산 원시데이터유형과연산 원시데이터유형과연산 숫자데이터유형 - 숫자데이터유형 원시데이터유형과연산 표준입출력함수 - printf 문 가장기본적인출력함수. (stdio.h) 문법 ) printf( Test printf. a = %d \n, a); printf( %d, %f, %c \n, a, b, c); #include #include

More information

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

Microsoft PowerPoint 자바-기본문법(Ch2).pptx 자바기본문법 1. 기본사항 2. 자료형 3. 변수와상수 4. 연산자 1 주석 (Comments) 이해를돕기위한설명문 종류 // /* */ /** */ 활용예 javadoc HelloApplication.java 2 주석 (Comments) /* File name: HelloApplication.java Created by: Jung Created on: March

More information

Microsoft PowerPoint - chap03-변수와데이터형.pptx

Microsoft PowerPoint - chap03-변수와데이터형.pptx #include int main(void) { int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num %d\n", num); return 0; } 1 학습목표 의 개념에 대해 알아본다.

More information

Microsoft PowerPoint - chap06-2pointer.ppt

Microsoft PowerPoint - chap06-2pointer.ppt 2010-1 학기프로그래밍입문 (1) chapter 06-2 참고자료 포인터 박종혁 Tel: 970-6702 Email: jhpark1@snut.ac.kr 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- 포인터의정의와사용 변수를선언하는것은메모리에기억공간을할당하는것이며할당된이후에는변수명으로그기억공간을사용한다. 할당된기억공간을사용하는방법에는변수명외에메모리의실제주소값을사용하는것이다.

More information

컴파일러

컴파일러 YACC 응용예 Desktop Calculator 7/23 Lex 입력 수식문법을위한 lex 입력 : calc.l %{ #include calc.tab.h" %} %% [0-9]+ return(number) [ \t] \n return(0) \+ return('+') \* return('*'). { printf("'%c': illegal character\n",

More information

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Function) 1. 함수의개념 입력에대해적절한출력을발생시켜주는것 내가 ( 프로그래머 ) 작성한명령문을연산, 처리, 실행해주는부분 ( 모듈 ) 자체적으로실행되지않으며,

More information

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout << " 양수입력 : "; cin >> *p; if (*p <= 0) cout << " 양수를입력해야합니다 " << endl; return; 동적할

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout <<  양수입력 : ; cin >> *p; if (*p <= 0) cout <<  양수를입력해야합니다  << endl; return; 동적할 15 장기타주제들 auto_ptr 변환함수 cast 연산자에의한명시적형변환실행시간타입정보알아내기 (RTTI) C++ 프로그래밍입문 1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout > *p; if (*p

More information

11장 포인터

11장 포인터 누구나즐기는 C 언어콘서트 제 9 장포인터 이번장에서학습할내용 포인터이란? 변수의주소 포인터의선언 간접참조연산자 포인터연산 포인터와배열 포인터와함수 이번장에서는포인터의기초적인지식을학습한다. 포인터란? 포인터 (pointer): 주소를가지고있는변수 메모리의구조 변수는메모리에저장된다. 메모리는바이트단위로액세스된다. 첫번째바이트의주소는 0, 두번째바이트는 1, 변수와메모리

More information

슬라이드 1

슬라이드 1 정적메모리할당 (Static memory allocation) 일반적으로프로그램의실행에필요한메모리 ( 변수, 배열, 객체등 ) 는컴파일과정에서결정되고, 실행파일이메모리에로드될때할당되며, 종료후에반환됨 동적메모리할당 (Dynamic memory allocation) 프로그램의실행중에필요한메모리를할당받아사용하고, 사용이끝나면반환함 - 메모리를프로그램이직접관리해야함

More information

Microsoft PowerPoint - C++ 5 .pptx

Microsoft PowerPoint - C++ 5 .pptx C++ 언어프로그래밍 한밭대학교전자. 제어공학과이승호교수 연산자중복 (operator overloading) 이란? 2 1. 연산자중복이란? 1) 기존에미리정의되어있는연산자 (+, -, /, * 등 ) 들을프로그래머의의도에맞도록새롭게정의하여사용할수있도록지원하는기능 2) 연산자를특정한기능을수행하도록재정의하여사용하면여러가지이점을가질수있음 3) 하나의기능이프로그래머의의도에따라바뀌어동작하는다형성

More information

Microsoft PowerPoint - ch07 - 포인터 pm0415

Microsoft PowerPoint - ch07 - 포인터 pm0415 2015-1 프로그래밍언어 7. 포인터 (Pointer), 동적메모리할당 2015 년 4 월 4 일 교수김영탁 영남대학교공과대학정보통신공학과 (Tel : +82-53-810-2497; Fax : +82-53-810-4742 http://antl.yu.ac.kr/; E-mail : ytkim@yu.ac.kr) Outline 포인터 (pointer) 란? 간접참조연산자

More information

6주차.key

6주차.key 6, Process concept A program in execution Program code PCB (process control block) Program counter, registers, etc. Stack Heap Data section => global variable Process in memory Process state New Running

More information

02 C h a p t e r Java

02 C h a p t e r Java 02 C h a p t e r Java Bioinformatics in J a va,, 2 1,,,, C++, Python, (Java),,, (http://wwwbiojavaorg),, 13, 3D GUI,,, (Java programming language) (Sun Microsystems) 1995 1990 (green project) TV 22 CHAPTER

More information

금오공대 컴퓨터공학전공 강의자료

금오공대 컴퓨터공학전공 강의자료 C 프로그래밍프로젝트 Chap 14. 포인터와함수에대한이해 2013.10.09. 오병우 컴퓨터공학과 14-1 함수의인자로배열전달 기본적인인자의전달방식 값의복사에의한전달 val 10 a 10 11 Department of Computer Engineering 2 14-1 함수의인자로배열전달 배열의함수인자전달방식 배열이름 ( 배열주소, 포인터 ) 에의한전달 #include

More information

PowerPoint Presentation

PowerPoint Presentation public class SumTest { public static void main(string a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두수를더하는부분입니다 System.out.println(" 두수의합은 " + sum +

More information

11장 포인터

11장 포인터 Dynamic Memory and Linked List 1 동적할당메모리의개념 프로그램이메모리를할당받는방법 정적 (static) 동적 (dynamic) 정적메모리할당 프로그램이시작되기전에미리정해진크기의메모리를할당받는것 메모리의크기는프로그램이시작하기전에결정 int i, j; int buffer[80]; char name[] = data structure"; 처음에결정된크기보다더큰입력이들어온다면처리하지못함

More information

C++ Programming

C++ Programming C++ Programming 연산자다중정의 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 연산자다중정의 C++ 스타일의문자열 2 연산자다중정의 연산자다중정의 단항연산자다중정의 이항연산자다중정의 cin, cout 그리고 endl C++ 스타일의문자열 3 연산자다중정의 연산자다중정의 (Operator

More information

<342EBAAFBCF620B9D720B9D9C0CEB5F92E687770>

<342EBAAFBCF620B9D720B9D9C0CEB5F92E687770> 예약어(reserved word) : 프로그래밍 언어에서 특별한 용도로 사용하고자 미리 지정한 단어 - 프로그램의 구성요소를 구별하게 해주는 역할 => 라벨, 서브 프로그램 이름, 변수에 연관되어 다른 변수나 서브 프로그램 등과 구별 - 식별자의 최대길이는 언어마다 각각 다르며 허용길이를 넘어서면 나머지 문자열은 무시됨 - FORTRAN, COBOL, HTML

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 3 if, if else, if else if, switch case for, while, do while break, continue : System.in, args, JOptionPane for (,, ) @ vs. logic data method variable Data Data Flow (Type), ( ) @ Member field

More information

Microsoft Word - ExecutionStack

Microsoft Word - ExecutionStack Lecture 15: LM code from high level language /* Simple Program */ external int get_int(); external void put_int(); int sum; clear_sum() { sum=0; int step=2; main() { register int i; static int count; clear_sum();

More information

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx #include int main(void) { int num; printf( Please enter an integer "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 을 작성하면서 C 프로그램의

More information

강의10

강의10 Computer Programming gdb and awk 12 th Lecture 김현철컴퓨터공학부서울대학교 순서 C Compiler and Linker 보충 Static vs Shared Libraries ( 계속 ) gdb awk Q&A Shared vs Static Libraries ( 계속 ) Advantage of Using Libraries Reduced

More information

Microsoft PowerPoint - PL_03-04.pptx

Microsoft PowerPoint - PL_03-04.pptx Copyright, 2011 H. Y. Kwak, Jeju National University. Kwak, Ho-Young http://cybertec.cheju.ac.kr Contents 1 프로그래밍 언어 소개 2 언어의 변천 3 프로그래밍 언어 설계 4 프로그래밍 언어의 구문과 구현 기법 5 6 7 컴파일러 개요 변수, 바인딩, 식 및 제어문 자료형 8

More information

A Dynamic Grid Services Deployment Mechanism for On-Demand Resource Provisioning

A Dynamic Grid Services Deployment Mechanism for On-Demand Resource Provisioning C Programming Practice (II) Contents 배열 문자와문자열 구조체 포인터와메모리관리 구조체 2/17 배열 (Array) (1/2) 배열 동일한자료형을가지고있으며같은이름으로참조되는변수들의집합 배열의크기는반드시상수이어야한다. type var_name[size]; 예 ) int myarray[5] 배열의원소는원소의번호를 0 부터시작하는색인을사용

More information

구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined data types) : 다양한자료형을묶어서목적에따라새로운자료형을

구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined data types) : 다양한자료형을묶어서목적에따라새로운자료형을 (structures) 구조체정의 구조체선언및초기화 구조체배열 구조체포인터 구조체배열과포인터 구조체와함수 중첩된구조체 구조체동적할당 공용체 (union) 1 구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined

More information

gnu-lee-oop-kor-lec06-3-chap7

gnu-lee-oop-kor-lec06-3-chap7 어서와 Java 는처음이지! 제 7 장상속 Super 키워드 상속과생성자 상속과다형성 서브클래스의객체가생성될때, 서브클래스의생성자만호출될까? 아니면수퍼클래스의생성자도호출되는가? class Base{ public Base(String msg) { System.out.println("Base() 생성자 "); ; class Derived extends Base

More information

JAVA PROGRAMMING 실습 08.다형성

JAVA PROGRAMMING 실습 08.다형성 2015 학년도 2 학기 1. 추상메소드 선언은되어있으나코드구현되어있지않은메소드 abstract 키워드사용 메소드타입, 이름, 매개변수리스트만선언 public abstract String getname(); public abstract void setname(string s); 2. 추상클래스 abstract 키워드로선언한클래스 종류 추상메소드를포함하는클래스

More information

Microsoft PowerPoint - a10.ppt [호환 모드]

Microsoft PowerPoint - a10.ppt [호환 모드] Structure Chapter 10: Structures t and Macros Structure 관련된변수들의그룹으로이루어진자료구조 template, pattern field structure를구성하는변수 (cf) C언어의 struct 프로그램의 structure 접근 entire structure 또는 individual fields Structure는

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 3 장함수와문자열 1. 함수의기본적인개념을이해한다. 2. 인수와매개변수의개념을이해한다. 3. 함수의인수전달방법 2가지를이해한다 4. 중복함수를이해한다. 5. 디폴트매개변수를이해한다. 6. 문자열의구성을이해한다. 7. string 클래스의사용법을익힌다. 이번장에서만들어볼프로그램 함수란? 함수선언 함수호출 예제 #include using

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 System Software Experiment 1 Lecture 5 - Array Spring 2019 Hwansoo Han (hhan@skku.edu) Advanced Research on Compilers and Systems, ARCS LAB Sungkyunkwan University http://arcs.skku.edu/ 1 배열 (Array) 동일한타입의데이터가여러개저장되어있는저장장소

More information

C++ Programming

C++ Programming C++ Programming 예외처리 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 예외처리 2 예외처리 예외처리 C++ 의예외처리 예외클래스와객체 3 예외처리 예외를처리하지않는프로그램 int main() int a, b; cout > a >> b; cout

More information

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어 개나리 연구소 C 언어 노트 (tyback.egloos.com) 프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어먹고 하더라구요. 그래서,

More information

자바 프로그래밍

자바 프로그래밍 5 (kkman@mail.sangji.ac.kr) (Class), (template) (Object) public, final, abstract [modifier] class ClassName { // // (, ) Class Circle { int radius, color ; int x, y ; float getarea() { return 3.14159

More information

chap 5: Trees

chap 5: Trees 5. Threaded Binary Tree 기본개념 n 개의노드를갖는이진트리에는 2n 개의링크가존재 2n 개의링크중에 n + 1 개의링크값은 null Null 링크를다른노드에대한포인터로대체 Threads Thread 의이용 ptr left_child = NULL 일경우, ptr left_child 를 ptr 의 inorder predecessor 를가리키도록변경

More information

untitled

untitled - -, (insert) (delete) - - (insert) (delete) (top ) - - (insert) (rear) (delete) (front) A A B top A B C top push(a) push(b) push(c) A B top pop() top A B D push(d) top #define MAX_STACK_SIZE 100 int

More information

<322EBCF8C8AF28BFACBDC0B9AEC1A6292E687770>

<322EBCF8C8AF28BFACBDC0B9AEC1A6292E687770> 연습문제해답 5 4 3 2 1 0 함수의반환값 =15 5 4 3 2 1 0 함수의반환값 =95 10 7 4 1-2 함수의반환값 =3 1 2 3 4 5 연습문제해답 1. C 언어에서의배열에대하여다음중맞는것은? (1) 3차원이상의배열은불가능하다. (2) 배열의이름은포인터와같은역할을한다. (3) 배열의인덱스는 1에서부터시작한다. (4) 선언한다음, 실행도중에배열의크기를변경하는것이가능하다.

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스, 객체, 메소드 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 필드만있는클래스 텔레비젼 2 예제 1. 필드만있는클래스 3 예제 2. 여러개의객체생성하기 4 5 예제 3. 메소드가추가된클래스 public class Television { int channel; // 채널번호 int volume; // 볼륨 boolean

More information

K&R2 Reference Manual 번역본

K&R2 Reference Manual 번역본 typewriter structunion struct union if-else if if else if if else if if if if else else ; auto register static extern typedef void char short int long float double signed unsigned const volatile { } struct

More information

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3 Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3 Example 3.1 Files 3.2 Source code 3.3 Exploit flow

More information

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2 제 17 장동적메모리와연결리스트 유준범 (JUNBEOM YOO) Ver. 2.0 jbyoo@konkuk.ac.kr http://dslab.konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다.

More information

Microsoft Word - FunctionCall

Microsoft Word - FunctionCall Function all Mechanism /* Simple Program */ #define get_int() IN KEYOARD #define put_int(val) LD A val \ OUT MONITOR int add_two(int a, int b) { int tmp; tmp = a+b; return tmp; } local auto variable stack

More information

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100 2015-1 프로그래밍언어 9. 연결형리스트, Stack, Queue 2015 년 5 월 4 일 교수김영탁 영남대학교공과대학정보통신공학과 (Tel : +82-53-810-2497; Fax : +82-53-810-4742 http://antl.yu.ac.kr/; E-mail : ytkim@yu.ac.kr) 연결리스트 (Linked List) 연결리스트연산 Stack

More information

Microsoft PowerPoint - Chapter 6.ppt

Microsoft PowerPoint - Chapter 6.ppt 6.Static 멤버와 const 멤버 클래스와 const 클래스와 static 연결리스트프로그램예 Jong Hyuk Park 클래스와 const Jong Hyuk Park C 의 const (1) const double PI=3.14; PI=3.1415; // 컴파일오류 const int val; val=20; // 컴파일오류 3 C 의 const (1)

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 5 장생성자와접근제어 1. 객체지향기법을이해한다. 2. 클래스를작성할수있다. 3. 클래스에서객체를생성할수있다. 4. 생성자를이용하여객체를초기화할수 있다. 5. 접근자와설정자를사용할수있다. 이번장에서만들어볼프로그램 생성자 생성자 (constructor) 는초기화를담당하는함수 생성자가필요한이유 #include using namespace

More information

A Hierarchical Approach to Interactive Motion Editing for Human-like Figures

A Hierarchical Approach to Interactive Motion Editing for Human-like Figures 단일연결리스트 (Singly Linked List) 신찬수 연결리스트 (linked list)? tail 서울부산수원용인 null item next 구조체복습 struct name_card { char name[20]; int date; } struct name_card a; // 구조체변수 a 선언 a.name 또는 a.date // 구조체 a의멤버접근 struct

More information

untitled

untitled int i = 10; char c = 69; float f = 12.3; int i = 10; char c = 69; float f = 12.3; printf("i : %u\n", &i); // i printf("c : %u\n", &c); // c printf("f : %u\n", &f); // f return 0; i : 1245024 c : 1245015

More information

Design Issues

Design Issues 11 COMPUTER PROGRAMMING INHERIATANCE CONTENTS OVERVIEW OF INHERITANCE INHERITANCE OF MEMBER VARIABLE RESERVED WORD SUPER METHOD INHERITANCE and OVERRIDING INHERITANCE and CONSTRUCTOR 2 Overview of Inheritance

More information

C 프로그래밍 언어 입문 C 프로그래밍 언어 입문 김명호저 숭실대학교 출판국 머리말..... C, C++, Java, Fortran, Python, Ruby,.. C. C 1972. 40 C.. C. 1999 C99. C99. C. C. C., kmh ssu.ac.kr.. ,. 2013 12 Contents 1장 프로그래밍 시작 1.1 C 10 1.2 12

More information

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074> 객체지향프로그램밍 (Object-Oriented Programming) 1 C++ popular C 객체지향 (object oriented) C++ C : 상위계층언어특징 + 어셈블리언어특징 C++ : 소프트웨어개발플랫폼에객체지향개념제공 객체지향 : 자료와이들자료를어떻게다룰것인지따로생각하지않고단지하나의사물로생각 형 변수가사용하는메모리크기 변수가가질수있는정보

More information

02장.배열과 클래스

02장.배열과 클래스 ---------------- DATA STRUCTURES USING C ---------------- CHAPTER 배열과구조체 1/20 많은자료의처리? 배열 (array), 구조체 (struct) 성적처리프로그램에서 45 명의성적을저장하는방법 주소록프로그램에서친구들의다양한정보 ( 이름, 전화번호, 주소, 이메일등 ) 를통합하여저장하는방법 홍길동 이름 :

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 9 강. 클래스의활용목차 멤버함수의외부정의 this 포인터 friend 선언 static 멤버 임시객체 1 /17 9 강. 클래스의활용멤버함수의외부정의 멤버함수정의구현방법 내부정의 : 클래스선언내에함수정의구현 외부정의 클래스선언 : 함수프로토타입 멤버함수정의 : 클래스선언외부에구현

More information

PowerPoint Presentation

PowerPoint Presentation Package Class 1 Heeseung Jo 목차 section 1 패키지개요와패키지의사용 section 2 java.lang 패키지의개요 section 3 Object 클래스 section 4 포장 (Wrapper) 클래스 section 5 문자열의개요 section 6 String 클래스 section 7 StringBuffer 클래스 section

More information

Microsoft PowerPoint - chap10-함수의활용.pptx

Microsoft PowerPoint - chap10-함수의활용.pptx #include int main(void) { int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 중 값에 의한 전달 방법과

More information

OCW_C언어 기초

OCW_C언어 기초 초보프로그래머를위한 C 언어기초 4 장 : 연산자 2012 년 이은주 학습목표 수식의개념과연산자및피연산자에대한학습 C 의알아보기 연산자의우선순위와결합방향에대하여알아보기 2 목차 연산자의기본개념 수식 연산자와피연산자 산술연산자 / 증감연산자 관계연산자 / 논리연산자 비트연산자 / 대입연산자연산자의우선순위와결합방향 조건연산자 / 형변환연산자 연산자의우선순위 연산자의결합방향

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Lecture 02 프로그램구조및문법 Kwang-Man Ko kkmam@sangji.ac.kr, compiler.sangji.ac.kr Department of Computer Engineering Sang Ji University 2018 자바프로그램기본구조 Hello 프로그램구조 sec01/hello.java 2/40 자바프로그램기본구조 Hello 프로그램구조

More information

Microsoft PowerPoint - chap06-5 [호환 모드]

Microsoft PowerPoint - chap06-5 [호환 모드] 2011-1 학기프로그래밍입문 (1) chapter 06-5 참고자료 변수의영역과데이터의전달 박종혁 Tel: 970-6702 Email: jhpark1@seoultech.ac.kr h k 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- ehanbit.net 자동변수 지금까지하나의함수안에서선언한변수는자동변수이다. 사용범위는하나의함수내부이다. 생존기간은함수가호출되어실행되는동안이다.

More information

JAVA PROGRAMMING 실습 05. 객체의 활용

JAVA PROGRAMMING 실습 05. 객체의 활용 public class Person{ public String name; public int age; } public Person(){ } public Person(String s, int a){ name = s; age = a; } public String getname(){ return name; } @ 객체의선언 public static void main(string

More information

Microsoft PowerPoint - 8ÀÏ°_Æ÷ÀÎÅÍ.ppt

Microsoft PowerPoint - 8ÀÏ°_Æ÷ÀÎÅÍ.ppt 포인터 1 포인터란? 포인터 메모리의주소를가지고있는변수 메모리주소 100번지 101번지 102번지 103번지 int theage (4 byte) 변수의크기에따라 주로 byte 단위 주소연산자 : & 변수의주소를반환 메모리 2 #include list 8.1 int main() using namespace std; unsigned short

More information

임베디드시스템설계강의자료 6 system call 2/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과

임베디드시스템설계강의자료 6 system call 2/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과 임베디드시스템설계강의자료 6 system call 2/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과 System call table and linkage v Ref. http://www.ibm.com/developerworks/linux/library/l-system-calls/ - 2 - Young-Jin Kim SYSCALL_DEFINE 함수

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 4 (Object) (Class) (Instance) (Method) (Constructor) Memory 1 UML 1 @ & 1 (Real World) (Software World) @ &.. () () @ & 2 (Real World) (Software World) OOA/ Modeling Abstraction Instantiation

More information

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 (   ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각 JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( http://java.sun.com/javase/6/docs/api ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각선의길이를계산하는메소드들을작성하라. 직사각형의가로와세로의길이는주어진다. 대각선의길이는 Math클래스의적절한메소드를이용하여구하라.

More information

SIGPLwinterschool2012

SIGPLwinterschool2012 1994 1992 2001 2008 2002 Semantics Engineering with PLT Redex Matthias Felleisen, Robert Bruce Findler and Matthew Flatt 2009 Text David A. Schmidt EXPRESSION E ::= N ( E1 O E2 ) OPERATOR O ::=

More information

Microsoft PowerPoint - chap12-고급기능.pptx

Microsoft PowerPoint - chap12-고급기능.pptx #include int main(void) int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; 1 학습목표 가 제공하는 매크로 상수와 매크로

More information

학습목차 2.1 다차원배열이란 차원배열의주소와값의참조

학습목차 2.1 다차원배열이란 차원배열의주소와값의참조 - Part2- 제 2 장다차원배열이란무엇인가 학습목차 2.1 다차원배열이란 2. 2 2 차원배열의주소와값의참조 2.1 다차원배열이란 2.1 다차원배열이란 (1/14) 다차원배열 : 2 차원이상의배열을의미 1 차원배열과다차원배열의비교 1 차원배열 int array [12] 행 2 차원배열 int array [4][3] 행 열 3 차원배열 int array [2][2][3]

More information

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a 6 장복사생성자 객체의생성과대입객체의값에의한전달복사생성자디폴트복사생성자복사생성자의재정의객체의값에의한반환임시객체 C++ 프로그래밍입문 1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y;

More information

05-class.key

05-class.key 5 : 2 (method) (public) (private) (interface) 5.1 (Method), (public method) (private method) (constructor), 3 4 5.2 (client). (receiver)., System.out.println("Hello"); (client object) (receiver object)

More information

Microsoft PowerPoint - 2강

Microsoft PowerPoint - 2강 컴퓨터과학과 김희천교수 학습개요 Java 언어문법의기본사항, 자료형, 변수와상수선언및사용법, 각종연산자사용법, if/switch 등과같은제어문사용법등에대해설명한다. 또한 C++ 언어와선언 / 사용방법이다른 Java의배열선언및사용법에대해서설명한다. Java 언어의효과적인활용을위해서는기본문법을이해하는것이중요하다. 객체지향의기본개념에대해알아보고 Java에서어떻게객체지향적요소를적용하고있는지살펴본다.

More information

Microsoft PowerPoint - additional06.ppt [호환 모드]

Microsoft PowerPoint - additional06.ppt [호환 모드] 보조자료 6.Static 멤버와 const 멤버 클래스와 const 클래스와 static 연결리스트프로그램예 Jong Hyuk Park 클래스와 const Jong Hyuk Park 복습 : Const 키워드왜사용? C 의 const (1) const double PI=3.14; PI=3.1415; // 컴파일오류 const int val; val=20; //

More information

Introduction o Type supports abstraction Data Types Real World 유한성 (finite) 추상화 (abstraction) Programming Language concrete representation

Introduction o Type supports abstraction Data Types Real World 유한성 (finite) 추상화 (abstraction) Programming Language concrete representation Introduction o Type supports abstraction Data Types Real World 유한성 (finite) 추상화 (abstraction) Programming Language concrete representation Programming Language Implementation SANGJI University KO Kwangman

More information

Microsoft PowerPoint - ch10 - 이진트리, AVL 트리, 트리 응용 pm0600

Microsoft PowerPoint - ch10 - 이진트리, AVL 트리, 트리 응용 pm0600 균형이진탐색트리 -VL Tree delson, Velskii, Landis에의해 1962년에제안됨 VL trees are balanced n VL Tree is a binary search tree such that for every internal node v of T, the heights of the children of v can differ by at

More information

슬라이드 1

슬라이드 1 Pairwise Tool & Pairwise Test NuSRS 200511305 김성규 200511306 김성훈 200614164 김효석 200611124 유성배 200518036 곡진화 2 PICT Pairwise Tool - PICT Microsoft 의 Command-line 기반의 Free Software www.pairwise.org 에서다운로드후설치

More information

PowerPoint Presentation

PowerPoint Presentation #include int main(void) { int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 변수와상수의개념에대해알아본다.

More information

슬라이드 1

슬라이드 1 3. 자료와변수 3.1 자료형 자료형 컴퓨터는숫자 (= 데이터 ) 를다룬다. 컴퓨터가다룰수있는숫자의유형이있다. C 언어에서의자료형 크기 (byte) 정수형 ( 문자형 ) char 1 정수형 실수형 ( 부동소수형 ) short 2 int 4 long 4 long long 8 float 4 double 8 long double 8 / 16 강 C 프로그래밍 3

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 5 강. 배열, 포인터, 참조목차 배열 포인터 C++ 메모리구조 주소연산자 포인터 포인터연산 배열과포인터 메모리동적할당 문자열 참조 1 /20 5 강. 배열, 포인터, 참조배열 배열 같은타입의변수여러개를하나의변수명으로처리 int Ary[10]; 총 10 개의변수 : Ary[0]~Ary[9]

More information

쉽게

쉽게 Power Java 제 4 장자바프로그래밍기초 이번장에서학습할내용 자바프로그램에대한기초사항을학습 자세한내용들은추후에. Hello.java 프로그램 주석 주석 (comment): 프로그램에대한설명을적어넣은것 3 가지타입의주석 클래스 클래스 (class): 객체를만드는설계도 ( 추후에학습 ) 자바프로그램은클래스들로구성된다. 그림 4-1. 자바프로그램의구조 클래스정의

More information

Chapter 4. LISTS

Chapter 4. LISTS C 언어에서리스트구현 리스트의생성 struct node { int data; struct node *link; ; struct node *ptr = NULL; ptr = (struct node *) malloc(sizeof(struct node)); Self-referential structure NULL: defined in stdio.h(k&r C) or

More information

Microsoft PowerPoint - chap11-포인터의활용.pptx

Microsoft PowerPoint - chap11-포인터의활용.pptx #include int main(void) int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; 1 학습목표 포인터를 사용하는 다양한 방법에

More information

2002년 2학기 자료구조

2002년 2학기 자료구조 자료구조 (Data Structures) Chapter 1 Basic Concepts Overview : Data (1) Data vs Information (2) Data Linear list( 선형리스트 ) - Sequential list : - Linked list : Nonlinear list( 비선형리스트 ) - Tree : - Graph : (3)

More information

HW5 Exercise 1 (60pts) M interpreter with a simple type system M. M. M.., M (simple type system). M, M. M., M.

HW5 Exercise 1 (60pts) M interpreter with a simple type system M. M. M.., M (simple type system). M, M. M., M. 오늘할것 5 6 HW5 Exercise 1 (60pts) M interpreter with a simple type system M. M. M.., M (simple type system). M, M. M., M. Review: 5-2 7 7 17 5 4 3 4 OR 0 2 1 2 ~20 ~40 ~60 ~80 ~100 M 언어 e ::= const constant

More information

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf(hihi\n); } warning: conflicting types for functiona 이름 : 학번 : A. True or False: 각각항목마다 True 인지 False 인지적으세요. 1. (Python:) randint 함수를사용하려면, random 모듈을 import 해야한다. 2. (Python:) '' (single quote) 는한글자를표현할때, (double quote) 는문자열을표현할때사용한다. B. 다음에러를수정하는방법을적으세요.

More information

PowerPoint Template

PowerPoint Template 16-1. 보조자료템플릿 (Template) 함수템플릿 클래스템플릿 Jong Hyuk Park 함수템플릿 Jong Hyuk Park 함수템플릿소개 함수템플릿 한번의함수정의로서로다른자료형에대해적용하는함수 예 int abs(int n) return n < 0? -n : n; double abs(double n) 함수 return n < 0? -n : n; //

More information

No Slide Title

No Slide Title Copyright, 2001 Multimedia Lab., CH 3. COM object (In-process server) Eun-sung Lee twoss@mmlab.net Multimedia Lab. Dept. of Electrical and Computer Eng. University of Seoul Seoul, Korea 0. Contents 1.

More information

Microsoft PowerPoint - additional08.ppt [호환 모드]

Microsoft PowerPoint - additional08.ppt [호환 모드] 8. 상속과다형성 (polymorphism) 상속된객체와포인터 / 참조자의관계 정적바인딩과동적바인딩 virtual 소멸자 Jong Hyuk Park 상속의조건 public 상속은 is-a 관계가성립되도록하자. 일반화 ParttimeStd 구체화 2 상속의조건 잘못된상속의예 현실세계와완전히동떨어진모델이형성됨 3 상속의조건 HAS-A( 소유 ) 관계에의한상속!

More information

OCW_C언어 기초

OCW_C언어 기초 초보프로그래머를위한 C 언어기초 3 장 : 변수와데이터형 2012 년 이은주 학습목표 변수와상수의개념에대해알아본다. 리터럴상수, 매크로상수, const 변수에대해알아본 다. C 언어의데이터형에대해알아본다. 2 목차 변수와상수 변수 상수 데이터형 문자형 정수형 실수형 sizeof 연산자 3 변수와상수 변수 : 값이변경될수있는데이터 상수 : 값이변경될수없는데이터

More information

61 62 63 64 234 235 p r i n t f ( % 5 d :, i+1); g e t s ( s t u d e n t _ n a m e [ i ] ) ; if (student_name[i][0] == \ 0 ) i = MAX; p r i n t f (\ n :\ n ); 6 1 for (i = 0; student_name[i][0]!= \ 0&&

More information

슬라이드 1

슬라이드 1 Array, Structure, and Pointer 2019 SANGJI University Kwang-Man Ko () 배열 (array) 이란? 같은형의변수를여러개만드는경우에사용 int A0, A1, A2, A3,,A9; int A[10]; 0 1 2 3 4 5 6 7 8 9 반복코드등에서배열을사용하면효율적인프로그래밍이가능 예 ) 최대값을구하는프로그램

More information

13주-14주proc.PDF

13주-14주proc.PDF 12 : Pro*C/C++ 1 2 Embeded SQL 3 PRO *C 31 C/C++ PRO *C NOT! NOT AND && AND OR OR EQUAL == = SQL,,, Embeded SQL SQL 32 Pro*C C SQL Pro*C C, C Pro*C, C C 321, C char : char[n] : n int, short, long : float

More information

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D> Power Java 제 8 장클래스와객체 I 이번장에서학습할내용 클래스와객체 객체의일생직접 메소드클래스를 필드작성해 UML 봅시다. QUIZ 1. 객체는 속성과 동작을가지고있다. 2. 자동차가객체라면클래스는 설계도이다. 먼저앞장에서학습한클래스와객체의개념을복습해봅시다. 클래스의구성 클래스 (class) 는객체의설계도라할수있다. 클래스는필드와메소드로이루어진다.

More information