Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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++ÓïÑÔÈëÃÅÆª¡¿ ÉîÈ뺯Êý

Ç°ÃæÒ»ÆªÎÒÃǽéÉÜÁ˽ṹÌ壬ÕâÆªÖÕÓÚÄܹ»½éÉܺ¯ÊýÁË¡£ÎªÊ²Ã´ÕâÃ´ËµÄØ£¿ÒòΪº¯Êý·Ç³£ÖØÒª¡£¾ÍÕâô¼òµ¥¡£ºÙºÙ£¡Ö®ËùÒÔÔÚÕâʱ²Å½²º¯Êý£¬ÊÇÒòΪ±¾Æª½«ÁªÏµµ½Ç°ÃæµÄÿһƪ£¬ÕâÑùº¯Êý²ÅÄÜÌåÏÖµÄ͸³¹¡£ÄÇÎÒÃÇ¾ÍÆÈ²»¼°´ýµÄÇÐÈëÕýÌâ¡£
´ÓµÚһƪHelloworld¿ªÊ¼µ½ÏÖÔÚ£¬¾ÍûÓÐÍÑÀ뺯Êý¡£ÄǾÍÊÇÎÒÃǵÄmainº¯Êý¡£mainº¯ÊýÒ²ÊÇÒ»¸öÆÕͨµÄ ......

Åú´¦Àí µ÷ÊÔC/C++ʱɾ³ýÎÞÓõÄÎļþ

@echo --------------------- ÓÃÓÚ¡¶Ò»¸ö²Ù×÷ϵͳµÄʵÏÖ¡·µÄ cmd ---------------------
@echo off
mode con cols=80 lines=60 ::ǰһ¸öÊý×Ö»ò×ÖĸΪ±³¾°É«£¬ºóÒ»¸öÊý×Ö»òÕß×ÖĸΪǰ¾°É«£¬ÏÂÃæÊÇһЩÑÕÉ«¶ÔÓ¦µÄÊý×Ö»ò×Öĸ£º
::0£½ºÚ¡¢1£½À¶¡¢2£½ÂÌ¡¢3£½Ç³ÂÌ¡¢4£½ºì¡¢5£½×Ï¡¢6£½»Æ¡¢7=°×¡¢8=»Ò¡¢9=µ­À¶¡¢A£½µ ......

Linux CÓïÑÔѧϰ±Ê¼Ç

1¡¢int    4×Ö½Ú
   long   8×Ö½Ú
   float  4×Ö½Ú
   double 8×Ö½Ú
   long double 16×Ö½Ú
2¡¢Ò»¸ö×Ö·û±äÁ¿Ö»ÄÜ´æ·ÅÒ»¸ö×Ö·û¡¢Ò»¸ö×Ö½Ú´æ·ÅÒ»¸ö×Ö½Ú
   char c;
   c = 'a';    c = '\034'   ......

ÏÔʾµ¥ÔµÄÈÕÀúµÄC³ÌÐò

ÌâÄ¿ÈçÏ£º
ÒªÇóÏÔʾ³öµ¥ÔµÄÈÕÀú£¬Óû§ËµÃ÷Õâ¸öÔµÄÌìÊýºÍ±¾ÔÂµÄÆðʼÈÕÊÇÐÇÆÚ¼¸£¬¼´¿ÉÊä³ö¸ÃÔµÄÈÕÀú¡£
¾ÍÊÇÕâôһµÀ¼òµ¥µÄ³ÌÐò£¬ÎÒ±ïÁËÁ½Ìì×ÜËãŪ³öÀ´ÁË£¬½á¹ûËäÈ»´ïµ½ÁËÒªÇ󣬵«¾àÀëÎÒÔ¤ÏëµÄ»¹ÓÐÒ»¶Î²î¾à£¬ÏȰѳÌÐò
´úÂë·ÅÔÚÉÏÃæ£¬Ï£Íû´ó¼Ò¶àÌáÐÞ¸ÄÒâ¼û¡£
/******************************************************* ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ