U E D R , A S I H C RSS

C/C++어려운선언문해석하기

{{|
CodeProject . . .



문 : How to interpret complex C/C++ declarations (http://www.codeproject.com/cpp/complex_declarations.asp)





int * (* (*fp1) (int) ) 10; ? 런 C/C++

. 매

. 는 const typedef 및

" " .



.

.







int a;



'변 n int ' .



면,



int *p;



'변 p를 int * ' 면 '변 p를 int '

. (*) (&)는 변 (int)(p)

. . (: C++ Bjarne

Stroustrup는 변 .) (: B. S.는 는 무 만 남

. 면 더 를 보 . http://www.research.att.com/~bs/bs_faq2.html#whitespace )



int* p,q;



면 변 p q int를 (int *) 변 럼 보.

p만 int를 q는 int . (: int *p; int *q;

.)



리는 .



char **argv;



리만 따 는 무 . 따 리는 float

. 몇 .



문들. (: .

.)



int RollNum304;

int (*p)4=RollNum;

int *q5;



p는 int 4 (a pointer to an array of 4 ints)며, 변 q는 int

5(an array of 5 pointer to integers) .





const modifier

const 는 변 (변 <-> 변 ? 모 ) . const 변

. 변 .



const int n = 5;

int const m = 10;



n m const . C++

는 const .



const . 를 들 p, q .



const int *p;

int const *q;



, const int int 는 const .



const int를 . int 는 const .



int * const r = &n; // n int



p q는 const int *p *q . r const

r = &m . (물 m 른 int) 물 *r

.



const int 는 const .



const int * const p = &n; // n const int



문들면 const를 . 몇몇

는데 . ( )





char ** p1; // pointer to pointer to char

const char **p2; // pointer to pointer to const char

char * const * p3; // pointer to const pointer to char

const char * const * p4; // pointer to const pointer to const char

char ** const p5; // const pointer to pointer to char

const char ** const p6; // const pointer to pointer to const char

char * const * const p7; // const pointer to const pointer to char

const char * const * const p8; // const pointer to const pointer to const char



typedef

typedef는 typedef는 "* 는 & " . typedef 를



typedef char * PCHAR;

PCHAR p,q;



p, q 모 char를 . typedef 면 q는 char를 char 모르는 .



typedef를 문들 .



typedef char * a; // a is a pointer to a char

//

// a는

// char



typedef a b(); // b is a function that returns

// a pointer to a char

//

// b는

// char 를 리

//



typedef b *c; // c is a pointer to a function

// that returns a pointer to a char

//

// c는

// char

//

//



typedef c d(); // d is a function returning

// a pointer to a function

// that returns a pointer to a char

//

// d는

// char 를 리

//

// 를 리

//



typedef d *e; // e is a pointer to a function

// returning a pointer to a

// function that returns a

// pointer to a char

//

// e는

// char 를 리

//

// 를 리

//

//



e var10; // var is an array of 10 pointers to

// functions returning pointers to

// functions returning pointers to chars.

//

// var는

// char 를 리

//

// 를 리

//

// 10



typedef는 보 struct는 . struct 면 C++ 뿐만 C

struct를 .



typedef struct tagPOINT

{

int x;

int y;

}POINT;



POINT p; /* C */




는데 . 는 DOS

램(TSR) 는데 Win32 X-Windows는 callback 는데 .

. 를 들 블, STL 릿 Win NT/2K/XP

. .



int (*p)(char);



p를 char를 int를 리(a pointer to a function that takes a char

argument and return an int) .



float를 char를 를 리(a pointer to a

function that take two floats and returns a pointer to a pointer to a char)는 .



char ** (*p)(float, float);



면 char를 는 const void 를 리 5

(an array of 5 pointers to functions that receive two const pointers to chars and return void pointer)

?



void * (*a5)(char * const, char * const);



()

.



. .

바뀌 . ( : " 바뀐" 는 바를 . ).

. 모 .



"Start reading the declaration from the innermost parentheses, go right, and then go left. When you encounter parentheses, the

direction should be reversed. Once everything in the parentheses has been parsed, jump out of it. Continue till the whole

declaration has been parsed."



:

.



.



int * (* (*fp1) (int) ) 10;



1. 변 . --- fp1

2. ) 말 보면 * --- . 는 3. .

3. 를 벗 보면 (int) . --- 데 int를 받는.

4. 면 * . - 를 리는데 는 4.를 .

5. 를 벗 보면 10 . --- 10.

6. 보면 * . --- 배 는 7.를 .

7. 더 보면 int . --- int .



. .



"fp1 int 10 를 리 int를 받는

".





1. Start from the variable name -------------------------- fp1

2. Nothing to right but ) so go left to find * -------------- is a pointer

3. Jump out of parentheses and encounter (int) --------- to a function that takes an int as argument

4. Go left, find * ---------------------------------------- and returns a pointer

5. Jump put of parentheses, go right and hit 10 -------- to an array of 10

6. Go left find * ----------------------------------------- pointers to

7. Go left again, find int -------------------------------- ints.





.



int *( *( *arr5)())();



1. 변 . --- arr

2. 보면 5 . --- 5.

3. 보면 * . --- 배 데 4.를 .

4. 를 벗 보면 () . --- .

5. 보면 * . --- 를 리는데 는 6. .

6. 를 벗 보면 () . --- .

7. 보면 * . --- 를 리는데 는 8. .

8. 더 보면 int . --- int .



"arr int 를 리 를 리

5".



1. Start from the variable name --------------------- arr

2. Go right, find array subscript --------------------- is an array of 5

3. Go left, find * ----------------------------------- pointers

4. Jump out of parentheses, go right to find () ------ to functions

5. Go left, encounter * ----------------------------- that return pointers

6. Jump out, go right, find () ----------------------- to functions

7. Go left, find * ----------------------------------- that return pointers

8. Continue left, find int ----------------------------- to ints.






( : - 보면

.)



float ( * ( *b()) [] )(); // b is a function that returns a

// pointer to an array of pointers

// to functions returning floats.

//

// () b는 를 리.

// 는 배 는데 배 .

// 는데 는 float를 리.

//

// () b는 float를 리

// 는 배

// 리.



void * ( *c) ( char, int (*)()); // c is a pointer to a function that takes

// two parameters:

// a char and a pointer to a

// function that takes no

// parameters and returns

// an int

// and returns a pointer to void.

//

// () c는 .

// 는 char

// int .

// 를 리는데 는 void를 .

//

// () c는 void를 를 리

// char int를 리

// .



void ** (*d) (int &,

char **(*)(char *, char **)); // d is a pointer to a function that takes

// two parameters:

// a reference to an int and a pointer

// to a function that takes two parameters:

// a pointer to a char and a pointer

// to a pointer to a char

// and returns a pointer to a pointer

// to a char

// and returns a pointer to a pointer to void

//

// () d는 .

// 는 int .

//

// char를

// char를

// char를 를 리.

// 는 void를 를 리.

//

// () d는 void를 를 리

// int

// char를

// char를

// char를 를 리

//

// .

// ~~~



float ( * ( * e10)

(int &) ) 5; // e is an array of 10 pointers to

// functions that take a single

// reference to an int as an argument

// and return pointers to

// an array of 5 floats.

//

// () e는 10 .

// 는데 는 int

// 를 리.

// 5 는데 배 는 float.

//

// () e는 float 5

// 를 리

// int

// 10.





.

를 복.



int (CFoo::*p)(); // p is a pointer to a method in class CFoo

// that takes no argument and return an int

//

// () p는 CFoo .

// 무런 int를 리.

//

// () p는 무런 int를 리

// CFoo .



(calling convetion)

.



int (__stdcall* q)(); // q is a pointer to a __stdcall function

// that takes no argument and return int

//

// () q는 는 __stdcall .

// 무런 int를 리.

//

// () q는 무런 int를 리

// __stdcall .
|}}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:47
Processing time 0.0589 sec