C์ธ์ด Chapter 27
๐ก static ๋ณ์์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์๋ ์ปดํ์ผ์์ ์ฃผ์๊ฐ์ด ๊ณ ์ ๋๋ค. ์คํ๋ ๋ ๋ง๋ค์ด์ง๋ ์ฃผ์๋ ๋ค์ด๋๋ฏน ๋ณ์์ด๊ณ , (heap, stack), ์คํ๋๊ธฐ ์ ์ ๋ง๋ค์ด ์ง๋ ์ฃผ์๋ ์ ์ญ๋ณ์๋ค.(code, data, BSS)
๊ตฌ์กฐ์ฒด๋ฅผ ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ ๋ณ์
- ๊ตฌ์กฐ์ฒด ๋ฅผ ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ๋ณ์๋ ์ผ๋ฐ ํฌ์ธํฐ ๋ณ์์ ๋์ผํ๋ค.
- ํฌ์ธํฐ ๋ณ์๋ก ๊ตฌ์กฐ์ฒด์ ์ ๊ทผํ ๋๋ ๋ํธํ๊ธฐ๋์ ํ์ดํ๋ฅผ ์ฌ์ฉ.
- ์ ์ ๋์ผํ์ง๋ง ์ผ๋ฐ์ ์ผ๋ก ํ์ดํ๋ฅผ ๋ง์ด ์ฌ์ฉํ๋ค.
๐ Ex) ๋ฐ์ดํฐ ํ์ผ์์ ํค์ ๋ชธ๋ฌด๊ฒ๋ฅผ ์ฝ์ด ๋น๋ง์ ์ฒดํฌํ๋ ํ๋ก๊ทธ๋จ

๐ก ํ๋ก๊ทธ๋จ ์ค๋ช
- ์์ ๊ฐ์ ๊ตฌ์กฐ์ฒด ํฌ์ธํฐ ์ฌ์ฉ๋ฒ์ ์ค์ ์๋๊ณ ์์ค๋ฅผ ๋ถ์ ํ ๊ฒ
[ d9-5.dat ํ์ผ ]

< ์คํ ๊ฒฐ๊ณผ >

๊ตฌ์กฐ์ฒด๋ฅผ ํจ์์ ์ธ์๋ก ์ ๋ฌํ๋ ๋ฐฉ๋ฒ
- ๊ตฌ์กฐ์ฒด๋ ํจ์์ ์ธ์๋ ํจ์์ ๋ฐํ๊ฐ์ผ๋ก ์ฌ์ฉ๋ ์ ์๋ค.
- ๊ตฌ์กฐ์ฒด ์์ฒด๋ฅผ ์ ๋ฌํ๋ ๋ฐฉ๋ฒ๊ณผ ๊ตฌ์กฐ์ฒด ์ฃผ์๋ฅผ ์ ๋ฌํ๋ ๋ฐฉ๋ฒ์ด ์๋ค.
๐ Ex) ๋ ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ.
- ๊ตฌ์กฐ์ฒด์ ๋ฉค๋ฒ๋ฅผ ํจ์์ ์ธ์๋ก ์ ๋ฌํ๋ ๊ฒฝ์ฐ

๐ Ex) ๊ตฌ์กฐ์ฒด๋ฅผ ์ธ์๋ก ์ ๋ฌ ํ๋ ๋ฐฉ๋ฒ
- ๊ตฌ์กฐ์ฒด ๋ณ์๋ฅผ ํจ์์ ์ธ์๋ก ์ ๋ฌํ๋ ๊ฒฝ์ฐ

๐ Ex) ๊ตฌ์กฐ์ฒด์ ์ฃผ์๋ฅผ ์ธ์๋ก ์ ๋ฌํ๋ ๋ฐฉ๋ฒ
- ๊ตฌ์กฐ์ฒด์ ์ฃผ์๋ฅผ ์ธ์๋ก ์ ๋ฌํ๋ ๋ฐฉ๋ฒ

ํ๋ก๊ทธ๋จ ์ค๋ช
- ์ฒซ๋ฒ์งธ ์์ ๋๋ฒ์งธ ์์ ์ ๊ฒฝ์ฐ๋ ์๋์ฐจ์ด๊ฐ ๋ฏธ๋ฌํ๋ค.
- ์ธ๋ฒ์งธ ์์ ์ ์ฃผ์๊ฐ์ ์ ๋ฌํ๋ ๋ฐฉ๋ฒ์ด ๊ฐ์ฅ ๋น ๋ฅธ ํํ์ด๋ค.
< ์คํ ๊ฒฐ๊ณผ >

์ฐ๊ฒฐ๋ฆฌ์คํธ
Ex) ์ฐ๊ฒฐ๋ฆฌ์คํธ์ ๊ธฐ๋ณธํํ

ํ๋ก๊ทธ๋จ ์ค๋ช
- 1์ ์ถ๋ ฅ ํ๋ ๋ฐฉ๋ฒ.
- A.idata
- P -> idata
- 2๋ฅผ ์ถ๋ ฅ ํ๋ ๋ฐฉ๋ฒ.
- B.idata
- A.next -> idata
- p -> next -> idata
- 3์ ์ถ๋ ฅ ํ๋ ๋ฐฉ๋ฒ.
- C.idata
- B.next -> idata
- p -> next -> next->idata
< ์คํ ๊ฒฐ๊ณผ >

heap
- ๋ฉ๋ชจ๋ฆฌ ์์ญ์ค heap ์ os(์ด์์ฒด์ )์์ ๊ด๋ฆฌ ํ๋ค.
- ํ์ํ ๋ฉ๋ชจ๋ฆฌ ์ฉ๋์ ์๋์ผ๋ก ๊ฐ์ ธ์์ ์ธ์์๋ค.
void *malloc(size_t size);
- ์ ํจ์๋ ๋ฉ๋ชจ๋ฆฌ ์์ฒญ ํจ์
- heap ์์ญ ์ด์ธ์ ๋ฉ๋ชจ๋ฆฌ ์์ญ์ auto ๋ฉ๋ชจ๋ฆฌ ์ด๋ค.
- ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ ๋น๋ฐ์ผ๋ฉด ๊ทธ๋ฉ๋ชจ๋ฆฌ๋ ๊ฐ๋ฐ์๊ฐ ๊ธฐ์ตํด์ผํ๋ค. (๊ฐ๋ฐ์ ์ธ์๋ ์์์๋ค.)
- <stdlib.h> ์ ์๋์ด ์๋ค
- ์ ํจ์๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋๋ ค์ฃผ๋ ํจ์์ด๋ค.
Ex) ์ฌ์ฉ ํ์์ ์

Ex) ๋ฉ๋ชจ๋ฆฌ ์์ญ๋ณ ์ด์ ๋ฆฌ

< ์คํ ๊ฒฐ๊ณผ >
์ปดํ์ผ ํ๊ฒฝ์๋ฐ๋ผ ์์ญ๋ณ ๋ฉ๋ชจ๋ฆฌ๊ฐ์ ๋ณํ ์ ์๋ค.
gcc ๊ฒฐ๊ณผ

cl ๊ฒฐ๊ณผ
