Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

˳ʱÕë·½·¨ ½â¶Á C ¸´ÔӺ궨Òå

[This was posted to comp.lang.c by its author, David Anderson, on 1994-05-06.]
The ``Clockwise/Spiral Rule''
By David Anderson
There is a technique known as the ``Clockwise/Spiral Rule'' which enables any C programmer to parse in their head any C declaration!
There are three simple steps to follow:
Starting with the unknown element, move in a spiral/clockwise direction; when ecountering the following elements replace them with the corresponding english statements:
[X] or [] => Array X size of... or Array undefined size of... (type1, type2) => function passing type1 and type2 returning... * => pointer(s) to...
Keep doing this in a spiral/clockwise direction until all tokens have been covered.
Always resolve anything in parenthesis first!
Example #1: Simple declaration
+-------+
| +-+ |
| ^ | |
char *str[10];
^ ^ | |
| +---+ |
+-----------+
Question we ask ourselves: What is str?
``str is an...
We move in a spiral clockwise direction starting with `str' and the first character we see is a `[' so, that means we have an array, so...
``str is an array 10 of...
Continue in a spiral clockwise direction, and the next thing we encounter is the `*' so, that means we have pointers, so...
``str is an array 10 of pointers to...
Continue in a spiral direction and we see the end of the line (the `;'), so keep going and we get to the type `char', so...
``str is an array 10 of pointers to char''
We have now ``visited'' every token; therefore we are done!
Example #2: Pointer to Function declaration
+--------------------+
| +---+ |
| |+-+| |
| |^ || |
char *(*fp)( int, float *);
^ ^ ^ || |
| | +--+|


Ïà¹ØÎĵµ£º

ÓÃCдµÄ3DÃÔ¹¬

          Boss˵£¬Òª¿´OpenGL£¬¿´ÁË¿ìÒ»¸öÔ£¬×ÜËã³öÁ˸öÏñÑùµÄ¶«Î÷£¬ÓÃCдÁ˸ö3DÃÔ¹¬£¬
ËäȻֻÓÐ350ÐÐ
       ´úÂ룬²»¹ý±ßѧ±ßд£¬×ã×ãдÁËÒ»ÖÜʱ¼ä£¬»¹ÊÇСÓгɾ͸еģ¬»î»î»î£¡
         &n ......

¡¾×ª¡¿¡¾C\C++ÓïÑÔÈëÃÅƪ¡¿ Êý×éÓëÖ¸Õë

Ç°ÃæÁ½Æª»ù±¾°ÑÖ¸Õë¸ø½éÉÜÍêÁË£¬ÏàÐÅ´ó¼Ò¶ÔÖ¸ÕëÒѾ­²»ÊÇÄÇôİÉúÁË¡£Ò²²»»áÒòΪָÕëºÍÊý×éÖ®¼äµÄ¹Øϵ¶øµ¼Ö»ìÏýÁË¡£´ó¼Ò¿ÉÄÜÒ²ÆȲ»¼°´ýÏëÁ˽âϺóÀ´µÄ֪ʶ¡£½ñÌìÎÒÃǾͽéÉÜϽṹÌå¡£
¶ÔÓڽṹÌ壬¼ÈÈ»½Ð½á¹¹Ì壬ÐÎÏóÉÏÎÒÃÇ¿ÉÒÔÀí½âÆä¾ÍÊÇÒ»¶ÑÊý¾Ý¼¯ºÏÔÚÒ»ÆðÐγÉÒ»¸ö½á¹¹¡£¾Í±ÈÈçÒ»¸öѧÉúµÄÐÅÏ¢°üÀ¨£ºÑ§ºÅ¡¢ÐÕÃû¡¢°à¼¶¡¢Äê ......

¡¾×ª¡¿¡¾C\C++ÓïÑÔÈëÃÅƪ¡¿ »ù±¾Êý¾ÝÀàÐÍ

ǰһƪÎÒÃǽéÉÜÁËÒ»¸ö¼òµ¥²»¹ýµÄhelloworld³ÌÐòÒý³öÏà¹ØÎÊÌâ¡£³Ã×Å»¹Ã»ÓÐÍüµôÄÇЩ˼¿¼·½Ê½µÄ¼ÇÒ䣬±¾Æª¼ÌÐøÑÓÐøÕâÖÖ˼ά·½Ê½µÄÀíÄ½éÉÜÒ»ÏÂCC++ÖеĻù±¾Êý¾ÝÀàÐÍ¡£Êý¾ÝÀàÐͲ»Çå³þµÄ»°ÔÚÒÔºóµÄ±à³ÌÖлáÓкܶàÃÕÍźÍÎÊÌâ¡£ÉõÖÁÒ»¸ö³ÌÐòµÄBUGÕÒ°ëÌìҲûÓÐÕÒ³öÀ´Ê±ÎªÊ²Ã´£¬½á¹û²Å·¢ÏÖÊǼӼõÒç³öÁË¡£¸ü¼ÓÑÏÖصĻ¹ÓÐдԽ½ç¡¢¶ÁÔ ......

±ïÁËÒ»Ì죬×îÖÕд³öÀ´Á˵ÄÇó×î´ó¹«Ô¼ÊýµÄ³ÌÐò£¨C£©

Ç°ÌìÍíÉÏÓöµ½Ò»Ì⣬±àд³ÌÐòÇó³ö×î´ó¹«ÒòÊý£¨×î´ó¹«Ô¼Êý£©£¬±¾ÄܵÄÎÒÏëÆðÀ´ÁËÊýѧÖÐÇó×î´ó¹«ÒòʽµÄ·½·¨£¬¿ÉÊÇÔÚ³ÌÐòʵ¼ùÉÏ
Ã÷ÏԵijöÁËÎÊÌ⣬Á½¸öÊýÒªÒ»¸öÒ»¸öµÄ½øÐвð½â£¬È»ºóÕÒµ½ÏàͬµÄ£¬Õâ¸ù±¾ÊÇÒ»ÌõËÀ·£¬Ë¼Ë÷Ò»Ò¹ÐÑÀ´£¬Í»È»±Å·¢Áé¸Ð£¬¿ÉÒÔ
ÓÃÁ½¸öÊý½øÐÐÈ¡ÓàÔËË㣬Èç¹ûÓàÊýΪÁãÔò×î´ó¹«ÒòÊýΪ±»³ýÊý£¬²»ÎªÁãÔòÓàÊýΪ×î ......

c ÓïÑÔÌõ¼þ±àÒë Ïê½â

Ô¤´¦Àí¹ý³ÌɨÃèÔ´´úÂ룬¶ÔÆä½øÐгõ²½µÄת»»£¬²úÉúеÄÔ´´úÂëÌṩ¸ø±àÒëÆ÷¡£¿É¼ûÔ¤´¦Àí¹ý³ÌÏÈÓÚ±àÒëÆ÷¶ÔÔ´´úÂë½øÐд¦Àí¡£
ÔÚCÓïÑÔÖУ¬²¢Ã»ÓÐÈκÎÄÚÔڵĻúÖÆÀ´Íê³ÉÈçÏÂһЩ¹¦ÄÜ£ºÔÚ±àÒëʱ°üº¬ÆäËûÔ´Îļþ¡¢¶¨Òåºê¡¢¸ù¾ÝÌõ¼þ¾ö¶¨±àÒëʱÊÇ·ñ°üº¬Ä³Ð©´úÂë¡£ÒªÍê³ÉÕâЩ¹¤×÷£¬¾ÍÐèҪʹÓÃÔ¤´¦Àí³ÌÐò¡£¾¡¹ÜÔÚÄ¿Ç°¾ø´ó¶àÊý±àÒëÆ÷¶¼°üº ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ