Cè¨èªã®static(http://d.hatena.ne.jp/propella/20070508/p1)
static local variableã®staticã¯ï½¢éçã¡ã¢ãªé åã«ããããï½£ã¨ããæå³ã§ãã
Cè¨èªã«ããã¦ã¯ãããã¯ã®å
å´ã§å®ç¾©ãããlocal variableã¯ãããã¯ã¹ã³ã¼ããå¤ããã¨ãã«é©å®ç ´æ£ãããã¨ããä»æ§ãããã¾ãããå¤ãã¯ãããã¹ã¿ãã¯ãã¬ã¼ã ãã¬ã¸ã¹ã¿ã§å®è£
ãã¦ãã¾ãã
ãããä½ããã®çç±ã§ã¹ã¿ãã¯ãã¬ã¼ã ãã¬ã¸ã¹ã¿ã«ã¨ã£ã¦ã»ãããªãã¨ãã«static修飾åã使ãã¾ããéçã¡ã¢ãªé åã¯ã大åå¤æ°ãªã©ã¨åæ§ã«ããã¼ããã¹ã¿ã¼ãã¢ããæã«ã¡ã¢ãªã確ä¿ããã¨ã³ããªãã¤ã³ãã«å
¥ãåã«ã®ã¿ã©ã³ã¿ã¤ã ãåæåãè¡ãã¾ãããã®åæåã®ã¿ã¤ãã³ã°ã®ããã«ãï½¢ãããã¯ãæãã¦ãå¤ãä¿æããç¶ããï½£ã¨ããå¯ä½ç¨ãèµ·ããã¾ãã
ï½¢ä½ããã®çç±ï½£ã¨ãã¦ã¯
- å¤æ°ãããããã¹ã¿ãã¯ãã¬ã¼ã ã«ã¨ããã¨ã«ãã£ã¦ãã¤ã³ããã¯ã¹ç¸å¯¾åç §ã§ããªããªã£ã¦ã¯ã¾ã
- 巨大ãªé åãåã£ã¦ããããã¹ã¿ãã¯ãããµãã
- ã£ã¦ããããã¹ã¿ãã¯ããªã¿ã¼ã³ã¢ãã¬ã¹ã ãã§ãã£ã±ããã£ã±ããªã»ã©çã
- ãããããã¹ã¿ãã¯ã¿ãããªä¸å®é·ãªã¡ã¢ãªé åãæä½éããåããªãã使ãå¤æ°ã¯ããããã確å®ãã¦ãªãã¨ã¡ã¢ãªå ã«å®è£ ãåã¾ããã¨ãä¿è¨¼ã§ããªãã
ã¨ãã£ããå®è£ ä¾åãªçç±ã°ãããèãããã¾ãã
ããã«å¯¾ãã¦ã大åå¤æ°ãé¢æ°ã«é¢ããstaticã¯å°ãæå³åããç°ãªãã¾ãããã®å ´åã®ï½¢éçï½£ã¨ã¯ãï½¢ã·ã³ãã«æ
å ±ãå¤é¨ã«æ±ããªã/å¤é¨ãããåç
§ãããªãï½£ã¨ãããã¨ãããã¾ãã
Cè¨èªã«ããã¦ãã°ãã¼ãã«ã¹ã³ã¼ãã«ããããã»ã¨ãã©ã®ãã®ã¯ãï½¢ã·ã³ãã«ï½£ã¨ãã¦å¤é¨ãããåç
§ãããããã®ã¨ãã¦èãã¾ããããã§ã®ï½¢å¤é¨ï½£ã¯ï½¢ã³ã³ãã¤ã«åä½ï½£ã«å¯¾ããå¤é¨ã®ãã¨ã§ãå
·ä½çã«ã¯ãªã³ã¯åã®ï½¢ãªãã¸ã§ã¯ããã¡ã¤ã«ï½£ãæãã¾ãã
ãªãã¸ã§ã¯ããã¡ã¤ã«ãã³ã³ãã¤ã«ããéãæªè§£æ±ºãªã·ã³ãã«ã«é¢ãã¦ã¯ãªã³ã¯æã«è§£æ¶ããã¨ããåæã§è©±ãé²ãã¾ãããã ãCè¨èªã¯åºæ¬çã«ï¼ãã¹ã§ã³ã³ãã¤ã«ãçµäºãããã¨ããå®è£
ä¸ã®çç±ããããããï½¢æªè§£æ±ºãªã·ã³ãã«ï½£ãªã®ãï½¢æªå®ç¾©ã®ã·ã³ãã«ï½£ãªã®ããåºå¥ãã¤ãã¾ããã
ããã§ãé¢æ°ã®ãããã¿ã¤ã宣è¨ãªã©ããã¦ãï½¢ãã®é¢æ°ãã©ããã«ãããåã¯ãããªæãï½£ã¨ãããã¨ãããããã宣è¨ããä¸ã§å®éã®å¼ã³åºããè¡ãã¾ãããã®å®£è¨ãããããï½¢ã©ããã«ããï½£ã®ã§ã¯ãªããï½¢å¿
ãåããªãã¸ã§ã¯ããã¡ã¤ã«ã«ããï½£ãã¨ãä¼ããããã®ãã®ãstaticã§ããéã«ï½¢å¤ã«ããå¯è½æ§ãããï½£ãã¨ã示ãã®ãexternã§ãã
å¯ä½ç¨ã¨ãã¦ãå¤é¨ã«ã·ã³ãã«ã解æ¾ããªãã¨ãããã¨ãããå¥ã®ãªãã¸ã§ã¯ããã¡ã¤ã«ã«åãååã®ã·ã³ãã«ããã£ã¦ããªã³ã¯æã«ã·ã³ãã«ã®è¡çªãèµ·ããã¾ãããããã«ãã£ã¦ããããï½¢ãã¡ã¤ã«ããã¼ã«ã«ãªåå空éã¨ãã¦æ±ãï½£ãã¨ãã§ãã¾ãã
â¦â¦ã§ãããã®ã¾ã£ããæå³ã®ç°ãªãï¼ã¤ã®ãã¨ã«åãäºç´èªãå²ãå½ã¦ãã®ã¯çµ¶å¯¾Cè¨èªã¨ãã¦ã¯å¤±æã ã¨æãã¾ãã
ãã¨ãã°ãè¦ç¿ãéå°å£«ã§ãã Florian ã®æãåã¯ãã ãããå¦æ ¡ã«å
¥ã£ã¦åå¹´ãããã§ãã®è¾ºã®è©±ãããã»ã¹ã®æã¤ã¡ã¢ãªæ§é (ã³ã¼ãããã¼ã¿ãã¹ã¿ãã¯ãªã©ã®é å)ã¨ãã³ã³ãã¤ã«åä½ï¼åå²ã³ã³ãã¤ã«ï¼ãå©ãè¾¼ã¾ããä¸ã§ãã£ã¨æããã¾ãããã©ãç¬å¦ã§ãã£ã¦ããåã¯å¤§æ¦ãã®è¾ºæ··åãã¦é
·ãç®ã«ãã£ã¦ã¾ã(^^;)ã
ã¨ãã«ãç確ãªå¤§åå¤æ°ã®ä½¿ç¨ãã§ããªãåã«éã£ã¦ãstatic local variableã使ã£ã¦ã¿ããï¼ï½¢å¤§åå¤æ°ãå¯è½ãªéã使ããªï½£ã¨ããæããæ²è§£ãã¦ããï¼ãç¡ç¯æã«static global variableãä½ã£ã¦ãã³ã³ãã¤ã«åä½ãè¨ãä¸ãã£ãå¾ã§ååå²ã§ããã«ã¯ã¾ã£ããï¼è¨è¨ãã¦ããªã人ãä¸æã«åå空éã使ãã¨é
·ãç®ã«ï¼ã¨ããå¾åãããã¾ãã
ç¬å¦ãªã©ã§è¦ãããã¨ã使ãã®ã¯ãã°ãããã®ã§ãããå°ãªãã¨ãæ£ç¢ºã«ç解ããã¾ã§ã¯ãstaticã¨ããæååãgrepã§è¦ã¤ãã度ã«ï½¢ãã®ã³ã¼ãå
¨é¨ä½ãç´ããï½£ã¨å°çã®å®£åããã¦ãã¾ãããã¨ããä½åè¡ãããã½ã¼ã¹ã§ãã£ãã¨ãã¦ã(^^;)ã
ã¾ããCè¨èªã®åºèªãããã¦ä½ã¬ãã«åãã®å°ã便å©ãªã¢ã»ã³ãã©ãæåãã¦ããçºãæãããªå®è£
ä¾åã®åé¡ãã¯ãªã¢ããããã®ä»æ¹ã®ãªãä»æ§ãããããªæ´å²ççµç·¯ã§æ··å¨ãã¦ããã¨ããçç±ã¯ããããªãã§ããªãã®ã§ããããã¡ãã¡ã«ãããã ä»æ§ãè¦ã度ã«ï½¢ããã¯ã©ãç´å¾ãã¦ãããããï½£ã¨ãã¤ãæ©ãã§ãã¾ãã
確ãã«K&Rã«ãæ¸ãã¦ã¯ãããã§ããã©â¦â¦é
·ããããã¥ãããã§ããããããã(^^;)ã