· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
CLangauge Complex Declaration

ÇÔ¼ö Æ÷ÀÎÅͳª º¹ÀâÇÑ ¼±¾ðÀÌ ³ª¿Ã °æ¿ì ´çȲÇÏÁö ¾Ê±â À§ÇØ ½±°Ô Àд ¹ý¿¡ ´ëÇØ ´Ù·ç°Ú½À´Ï´Ù.

ÀÏ´Ü °¡Àå ¸ÕÀú ´ÙÀ½ ¼¼ °³ ¸ñ·ÏÀ» ¿Ü¿ì½Ã±â ¹Ù¶ø´Ï´Ù:

¿¬»êÀÚÀд ¹ýÁÖÀÇ»çÇ×
*a pointer to
(...)a function(...) returning¿©±â¼­ "..."´Â ÀÎÀÚ ¸ñ·Ï(parameter list)ÀÓ
NarrayN of¿©±â¼­ NÀº ¹è¿­ Å©±â¸¦ ³ªÅ¸³¿

º¹ÀâÇÑ ¼±¾ðÀ» Àд ¹æ¹ýÀº ´ÙÀ½°ú °°½À´Ï´Ù:

  • À̸§(identifier)ÀÌ ÀÖ´Â °÷ºÎÅÍ Â÷·Ê´ë·Î Àд´Ù.
  • Àд ¼ø¼­´Â ¿¬»êÀÚ °áÇÕ ¼øÀ§°¡ ³ôÀº °ÍºÎÅÍ ÀдÂ?

À§ Ç¥¿¡ ³ª¿Â ¿¬»êÀÚ´Â "Àд ¹ý"¿¡ µû¶ó ÀеÇ, À§ Ç¥ÀÇ °ýÈ£´Â ÇÔ¼ö ¼±¾ðÀ» À§ÇÑ °ÍÀÔ´Ï´Ù. ¿¬»êÀÚ ¿ì¼± ¼øÀ§¸¦ º¯°æÇϱâ À§ÇÑ °ýÈ£´Â ÀÐÁö ¾Ê½À´Ï´Ù.

¿¹¸¦ µé¾î ¾Æ·¡ ¼±¾ðÀ» ÀÐ¾î º¾½Ã´Ù:

int *a;

¸ÕÀú À̸§À» ã¾Æ¾ß ÇÕ´Ï´Ù. À§ ¼±¾ð¿¡¼­ "a"°¡ À̸§À̴ϱî, "a"ºÎÅÍ Àо°¡¸é µË´Ï´Ù. a¿¡¼­ °¡Àå ¸ÕÀú °áÇÕÇÏ´Â ±âÈ£´Â "*"ÀÔ´Ï´Ù. µû¶ó¼­ À§ÀÇ Ç¥¸¦ Âü°í·Î ÇÏ¿© ÀÐÀ¸¸é ´ÙÀ½°ú °°½À´Ï´Ù:

a = a pointer to ...

±×·³ ÀÌÁ¦ ³ª¸ÓÁö´Â "int"À̹ǷΠ±×³É ÀнÀ´Ï´Ù:

a = a pointer to int

Áï "a"´Â int¸¦ °¡¸®Å°´Â Æ÷ÀÎÅÍ Å¸ÀÔÀÔ´Ï´Ù.

Á» ´õ ¾î·Á¿î ¿¹¸¦ µé¾îº¾½Ã´Ù.

int *(*foo)(int, int);

À§ ¿¹¿¡¼­ À̸§Àº "foo"À̹ǷÎ, foo¿¡¼­ºÎÅÍ ÀÐ¾î ³ª°¡¸é µË´Ï´Ù. °¡Àå ¸ÕÀú °áÇÕÇÏ´Â °ÍÀº "foo"¿Í ÇÔ²² °ýÈ£ ¾È¿¡ ÀÖ´Â "*"ÀÔ´Ï´Ù. Â÷·Ê´ë·Î Àд °ÍÀ» Ç¥·Î ³ªÅ¸³»¸é ´ÙÀ½°ú °°½À´Ï´Ù (ÇöÀç Àаí ÀÖ´Â ºÎºÐÀº @...@ »çÀÌÀÇ ºÎºÐÀÔ´Ï´Ù):

 int  * (@*foo@)(int, int) ;foo - a pointer to ...
 int  *@( *foo )(int, int)@;foo - a pointer to a function(int, int) returning ...
 int @* ( *foo )(int, int)@;foo - a pointer to a function(int, int) returning a pointer to ...
@int  * ( *foo )(int, int)@;foo - a pointer to a function(int, int) returning a pointer to int.

Áï ¿ì¸®¸»·Î ÀÐÀÚ¸é, "foo"´Â "int¸¦ °¡¸®Å°´Â Æ÷ÀÎÅ͸¦ ¸®ÅÏÇÏ´Â ÇÔ¼ö (ÀÎÀÚ´Â µÎ °³ÀÇ int)¸¦ °¡¸®Å°´Â Æ÷ÀÎÅÍ"¶ó ÇÒ ¼ö ÀÖ½À´Ï´Ù.

ÈçÈ÷ typedef¸¦ ½á¼­ À§¿Í °°Àº ÇÔ¼ö Æ÷ÀÎÅ͸¦ ´Ù¸¥ À̸§À¸·Î Á¤ÀÇÇÕ´Ï´Ù:

typedef int (*proc_t)(const void *);

ÀÌ °æ¿ì, "typedef"¸¦ »©°í ÀÐÀ¸¸é µË´Ï´Ù. Áï,

proc_ta pointer to function(const void *) returning int.

¹°·Ð "typedef"¸¦ ½èÀ¸¹Ç·Î ÀÌ´Â º¯¼ö ¼±¾ðÀÌ ¾Æ´Ï¶ó, »õ·Î¿î ŸÀÔÀ» Á¤ÀÇÇÑ °ÍÀÌÁÒ.

¸¶Áö¸·À¸·Î ÁÖÀÇÇÒ °ÍÀº, ÇÔ¼ö ÀÎÀÚ¿¡ À̸§ÀÌ ÀÖÀ» °æ¿ì, ¾î¶² °ÍÀÌ ±âÁØÀÌ µÇ´Â À̸§ÀÎÁö Àß ¾Ë°í Àоî¾ß ÇÕ´Ï´Ù. ¿¹¸¦ µé¾î:

int (*proc_t)(int type, const void *data);

¿©±â¼­ ±âÁØÀÌ µÇ´Â À̸§Àº "type", "data"°¡ ¾Æ´Ñ "proc_t"ÀÔ´Ï´Ù. µû¶ó¼­ proc_t¸¦ Çؼ®ÇÒ ¶§¿¡´Â "type"À̳ª "data"¿¡ ½Å°æ¾µ ÇÊ¿ä´Â ¾ø½À´Ï´Ù.

proc_ta pointer to function(int type, const void *data) returning int.

³¡ - [http]½Å¼º±¹


TODO. ¹è¿­ N¿¡ ´ëÇÑ ¿¹Á¦¸¦ ¸¸µé °Í.

TODO. ¿¹Á¦. "int (*ap)[30];", "(*(void(*)())0)();", "void (*(*signal)(int, void (*)(int)))(int);"¿¡ ´ëÇÑ ¼³¸íÀ» ³ÖÀ» °Í.


int (*ap)[30]
  int   (@*ap@)[30] ;ap - a pointer to ...
  int  @( *ap )[30]@;ap - a pointer to array[30] of
 @int   ( *ap )[30]@;ap - a pointer to array[30] of int

int *ap[30] (pointer arrays)
  int   *@ap[30]@ ;ap - an array[30] of ...
  int   @*ap[30]@ ;ap - an array[30] of a pointer to ...
  @int   *ap[30]@ ;ap - an array[30] of a pointer to int

void (*(*signal)(int,void(*)(int)))(int);
  void ( * (@*signal@)(int,void(*)(int)) )(int) ;signal - a pointer to ...
  void ( *@( *signal )(int,void(*)(int))@)(int) ;signal - a pointer to a function(int,void(*)(int)) returning ...
  void (@* ( *signal )(int,void(*)(int))@)(int) ;signal - a pointer to a function(int,void(*)(int)) returning a pointer to ...
  void@( * ( *signal )(int,void(*)(int)) )(int)@;signal - a pointer to a function(int,void(*)(int)) returning a pointer to a function(int) returning ...
 @void ( * ( *signal )(int,void(*)(int)) )(int)@;signal - a pointer to a function(int,void(*)(int)) returning a pointer to a function(int) returning void.

cf. Chapter 5.12 Complicated Declaration from K&R 2nd Ed.
  • int *f() /* f: function returning pointer to int */
  • int (*pf)() /* pf: pointer to function returning int */
  • char **argv /* argv: pointer to pointer to char */
  • int (*daytab)[13] /* daytab: pointer to array[13] of int */
  • int *daytab[13] /* daytab: array[13] of pointer to int */
  • void *comp() /* comp: function returning pointer to void */
  • void (*comp)() /* comp: pointer to function returning void */
  • char (*(*x())[])() /* x: function returning pointer to array[] of pointer to function returning char */
  • char (*(*x3)())5 /* x: array[3] of pointer to function returning pointer to array[5] of char */
  • ³»¿ë Ãß°¡ [¹Ú¿ë¹ü]
  • ³»¿ë Ãß°¡ cheeky

ID
Password
Join
You will be awarded some great honor.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2005-12-08 20:03:01
Processing time 0.0071 sec