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. 호했




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.0741 sec