๋‚ด ์ธ์ƒ์—์„œ ๋ฏฟ์„ ๊ฑด ์˜ค์ง ๋‚˜ ์ž์‹ ๋ฟ!

The only one you can truly trust is yourself.

๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ดˆ๋ณด๊ฐ€ ๊ฒช๋Š” ๋ฌธ์ œ๋“ค

for๋ฌธ๋„ ๋ชจ๋ฅด๋Š” ๋ฐ”๋ณด

๐ŸŽฎinspirer9 2021. 2. 3. 01:20
728x90
๋ฐ˜์‘ํ˜•

TCP/IP ์†Œ์ผ“ํ”„๋กœ๊ทธ๋ž˜๋ฐ C version์ด๋ผ๋Š” ์ฑ…์„ ๋ณด๊ณ ์žˆ๋Š”๋ฐ vํŽ˜์ด์ง€์˜ ์†Œ์Šค์ฝ”๋“œ๊ฐ€ ์ดํ•ด๊ฐ€ ์•ˆ๊ฐ€... ์–ด์ฐŒ๋œ๊ต...ใ… .ใ… ;

 

TCP/IP ์†Œ์ผ“ํ”„๋กœ๊ทธ๋ž˜๋ฐ C version

TCP/IP ์†Œ์ผ“ ํ”„๋กœ๊ทธ๋ž˜๋ฐ(The Pocket Guide to TCP/IP Sockets)์€ ์†Œ์ผ“์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ณต์žกํ•˜๊ณ  ๊ฐ•๋ ฅํ•œ ๋„คํŠธ์›Œํฌ ํ”„๋กœ๊ทธ๋žจ์„ ๊ฐœ๋ฐœํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์ง€์‹๊ณผ ๊ธฐ๋ฒ•๋“ค์„ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๋น ๋ฅด๊ณ  ์šฉ์ดํ•œ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ

www.yes24.com

๊ทผ๋ฐ ๊ฒ€์ƒ‰ํ•ด๋ณด๋‹ˆ ์ด๋ฏธ ์งˆ๋ฌธ์ด ์žˆ์–ดใ…‹
http://m.k.daum.net/qna/mobile/view.html?nk_type=Q&qid=49jtC

์•Œ๊ณ ๋ณด๋‹ˆ ๋‚ด๊ฐ€ ์ € ์†Œ์Šค์ฝ”๋“œ์˜ for ๋ฌธ์„ ์ž˜ ๋ชป ๋ณด๊ณ  ์žˆ์—ˆ๋˜ ๊ฑฐ์˜€๋‹ค.

์ž˜๋ณด๋ฉด for( ; ; )์—์„œ ๋งˆ์ง€๋ง‰ increment๊ฐ€ ์—†๋Š”๊ฑฐ.ใ…‹ใ…‹ใ…‹

์ด๋Ÿฌ๋‹ˆ ์ดํ•ด๋ฅผ ๋ชป ํ–ˆ์ง€. ํ‘ธํ•˜ํ•˜... ๋จธ๋ฆฌ๊ฐ€ ๋…น ์Šฌ์—ˆ๊ตฌ๋‚˜...

#include <iostream>
#include <cstdlib>

using namespace std;

typedef struct{
    int a;
    short s[2];
} MSG;

int main()
{
    MSG *mp, m = {4, 1, 102};
    char *fp, *tp;
    mp = (MSG*)malloc(sizeof(MSG));
    for(fp=(char*)m.s, tp=(char*)mp->s; tp < (char*)(mp+1);)
        *tp++ = *fp++;

    cout << "m.a:" << m.a << endl;
    cout << "m.s[0]:" << m.s[0] << endl;
    cout << "m.s[1]:" << m.s[1] << endl;
    cout << "m.a:" << mp->a << endl;
    cout << "m.s[0]:" << mp->s[0] << endl;
    cout << "m.s[1]:" << mp->s[1] << endl;

    return 0;
}

๊ฒฐ๊ณผ -- MSG์˜ int a ์ œ์™ธํ•œ s๋ถ€๋ถ„๋งŒ ๋ณต์‚ฌ

m.a:4
m.s[0]:1
m.s[1]:102
m.a:0
m.s[0]:1
m.s[1]:102

๊ทผ๋ฐ ๊ฒ€์ƒ‰ํ•ด๋ณด๋‹ˆ ์–ด๋”˜ ํ• ๋‹น๋ณด๋‹ค memcpy๊ฐ€ ๋” ๋น ๋ฅด๋‹ค๊ณ  ํ•˜๊ณ , ๋ฐ๋ธŒํ”ผ์•„๋ณด๋‹ˆ memcpy๋„ 4๋ฐ”์ดํŠธ์”ฉ ๋ณต์‚ฌํ•˜๋Š”๊ฑฐ๋ผ ๋˜‘๊ฐ™๋‹ค๊ณ  ํ•จ.

JoinC์— ์ •๋ฆฌ๋˜์–ด ์žˆ๋Š” ๋ฆฌ๋ˆ…์Šค ์‹œ์Šคํ…œ ์ฝœ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๋ณด๋‹ˆ memcpy๋Š” ํ•ด๋‹น ์‚ฌํ•ญ ์—†๋Š” ๋“ฏ. ๊ทธ๋Ÿผ ๊ฒฐ๋ก ์€ ํŽธํ•œ๋Œ€๋กœ, memcpy๋ฅผ ์“ฐ๋˜ ์œ„ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์“ฐ๋˜ ์ƒ๊ด€์—†๋Š”?

728x90
๋ฐ˜์‘ํ˜•