- Java
- Intellij
- emplace_back
- 우수한 프런트 개발자
- Interaction developer
- LSL_Script
- postman excel
- MFC
- 다빈치 리졸브
- Android/iOS Developer
- postman html parse
- postman collection
- Front-end developer
- solidity
- postman collection variables
- 프런트엔드
- postman pre-request
- C++
- 좋은 개발자
- Unity
- postman
- oracle
- web developer
- postman session
- c#
- Android
- postman csv
- postman automations
- UI/UX Engineer
- postman tests
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Today
- Total
david's daily developer note
[C,C++] 매크로로 구현한 Double linked list 본문
매크로 NEW(p, type)는 Pointer와 , 할당될 유형을 인자로 받고, Pointer P에 인자 type의 크기만큼, 메모리 할당한다.
인자 Type은 단순 built-in 자료형이나, UDT(User Define Type), class , struct등 모두 가능하다. 으흠~
매크로 ADD(head , p )는, 아래 정의된 structure Linked_List에 , 꼬리를 붙이는 작업을 한다. ㅎㅎ. 자료형은 일방향이 아니고, Double Linked_List이다. 뭐 대충 네모칸 그려놓고, 그리면서 따라가면 이해할 수 있다.
마지막, FREE(p)는 가비지 콜렉터가 없는 정말 LOW한 C언어에서의 메모리 반납 매크로이다.
#define NEW(p, type)if ((p = (type *) malloc(sizeof(type))) == NULL) { _tprintf(L"NEW : out of Memory!\n");}
#define ADD(head , p )if(head){p->next = head; p->prev = head->prev; head->prev = p ; p->prev->next = p;}
else{head = p; head->next = head->prev = p;}
#define FREE(p) if(p) {free ((char *) p ); p = NULL;}
struct Linked_List
{
int vnum; // index
tPointi v; // coordinates
tVertex next, prev;
};
'[Develop] Native > C++ , C' 카테고리의 다른 글
[C,C++] 실행파일이 만들어지는 단계 (0) | 2018.05.17 |
---|---|
[C,C++] 디버깅++ (0) | 2012.03.06 |
[C,C++] C++ Macro vs inline (0) | 2012.03.03 |
[C,C++] 클래스 전방 선언(Forward declarations)와 상호 참조 헤더 파일 (0) | 2012.02.21 |
[C,C++] 함수를 인자로 전달하는 방법 (2) | 2010.06.27 |