Cè¨èªããã°ã©ãã³ã°ã®è¦ãæ¸ãï¼æ¹è¨³ï¼
åæ: Notes on Programming in C
Rob Pike
1989å¹´2æ21æ¥
Copyright (C) 2003, Lucent Technologies Inc. and others. All Rights Reserved.
Lucent Public License Version 1.02
åæ¸ã
Kernighanã¨Plaugerã«ããâThe Elements of Programming Styleâ ï¼ãããã°ã©ã æ¸æ³ãæ¨ææ³è¨³ï¼ã¯éè¦ã§å½±é¿åã®ããæ¬ã§ãããã®æ¬ã«ã¯ããã ãã®ä¾¡å¤ãããã¾ãããããããã®ä¸ã®ç°¡æ½ãªã«ã¼ã«ããæ¬æ¥æå³ããããããªå²å¦ã®ç°¡æ½ãªè¡¨ç¾ã¨ãã¦ã§ã¯ãªããããã¹ã¿ã¤ã«ã®ã¬ã·ãã¨ãã¦åãåããã¦ããããã«ç§ã¯æã
æãã¾ãããã®æ¬ãå¤æ°åã¯æå³ãæã¤ããã«ã¤ããããã¹ãã ã¨è¨ããªããååã使ãæ¹ã説æããã¡ãã£ã¨ããã¨ãã»ã¤ã®ãããªãã®ã§ããã»ããããã¨ãããã¨ã«ãªãã®ã§ãããããMaximumValueUntilOverflow
㯠maxval
ãããããååã¨ãããã¨ã«ãªãã®ã§ãããããç§ã¯ããã¯æãã¾ããã
ããããè¿°ã¹ããã®ã¯ãèéã®å©ããªãã«ã¼ã«ã§ã¯ãªããå ¨ä½ã¨ãã¦ããã°ã©ãã³ã°ã®æ確ãã¨ããå²å¦ãä¿é²ãããããªçãã¨ãã»ã¤éã§ãããã¹ã¦ã«åæãã¦ããããã¨ã¯æãã¾ããããããã¯æè¦ã§ãããæè¦ã¯æã¨ã¨ãã«å¤ãããã®ã ããã§ãããããããããã®ãã¨ã¯ãææ¸ã¨ãã¦æ¸ãããã¨ã¯ããã¾ããã§ããããç§ã®é ã®ä¸ã«é·ãæéãããã¦èç©ãã¦ãããã®ã§ãå¤ãã®çµé¨ã«åºã¥ãã¦ãã¾ãããã®ããããããããã°ã©ã ã®è©³ç´°ãè¨ç»ããæ¹æ³ã«ã¤ãã¦ã®ç解ã®å©ãã«ãªãã°ã¨é¡ã£ã¦ãã¾ãï¼å ¨ä½ãè¨ç»ããæ¹æ³ã«ã¤ãã¦ã®ããã¨ãã»ã¤ãèªãã ãã¨ã¯ããã¾ãããããã®æç« ã¯ä¸é¨ããã«ã¤ãã¦æ¸ãã¦ãã¾ãï¼ãããå¤ãã£ã¦ããã¨æããã¦ããåé¡ããã¾ãããåæã§ããªãã¨ãã¦ããåé¡ããã¾ããããããããªãåæã§ããªãããèãã¦ããã ããã£ããã«ãªãã°ããã¡ãã®ã»ããæã¾ãããã¨ã§ãã決ãã¦ãç§ãããè¨ã£ãããããæ¸ãã¨ãããã¨ãããªãã§ãã ãããããã°ã©ã ã®ä¸ã§éæããããã¨ãæããã表ç¾ã§ããã¨ããªããèããããã«ããã°ã©ã ãã¦ãã ãããã¾ãããããä¸è²«ãã¦ã容赦ãªãè¡ã£ã¦ãã ããã
ããªãã®ã³ã¡ã³ãããå¾ ã¡ãã¦ãã¾ãã
表示ã®åé¡
ããã°ã©ã ã¯åºçç©ã®ãããªãã®ã§ããããã°ã©ã ã¯ããã°ã©ãèªèº«ãã»ãã®ããã°ã©ãï¼ããã¯æ°æ¥å¾ãæ°é±éå¾ãæ°å¹´å¾ã®ããªãèªèº«ããããã¾ããï¼ã«èªã¾ãããã®ã§ãããã¦æå¾ã«æ©æ¢°ã«èªã¾ããããã®ãã®ã§ããæ©æ¢°ã¯ãããã°ã©ã ã®è¦ãç®ã®ç¾ãããæ°ã«ãã¾ãããããã°ã©ã ãã³ã³ãã¤ã«ã§ããã°ãæ©æ¢°ã¯ããã§æºè¶³ã§ãããããã人éã¯ç¾ãããæ°ã«ãã¾ãããæ°ã«ããã¹ãã§ããæã ãããããã«ãªããã¨ãããã¾ããããªãã£ããªã³ããè¡ãããã°ã©ã ã¯ãããã°ã©ã ã®ã©ãã§ãããç´°ããã¨ããã強調ãããããªããããªåºåãèªåçã«è¡ãã¾ããããã¯æç« ã®å©è©ããã¹ã¦å¤ªåã§è¡¨ç¤ºããã®ã¨åãããã馬鹿ããããã¨ã§ããããã°ã©ã ã¯Algol-68 Reportã®ãããªè¦ãç®ãããªãã¨ãããªãï¼ã·ã¹ãã ã«ãã£ã¦ã¯ãã®ã¹ã¿ã¤ã«ã§ããã°ã©ã ãç·¨éããããå¼·å¶ãããããã¾ãï¼ã¨èãã人ã¯å¤ãã§ãããæçãªããã°ã©ã ã¯ãããªè¡¨ç¤ºããã¦ããã以ä¸æçã«ã¯ãªãã¾ããããã²ã©ãããã°ã©ã ã¯ç¬ã£ã¦ãã¾ããããªçµæã«ãªãã ãã§ãã
ãã¡ããã表示ã«ã¤ãã¦ã®ä¸è²«ããè¦ç´ã¯è¦ãç®ãããããããããããã«ã¯éè¦ãªãã®ã§ããã¤ã³ãã³ãã¯ãæãããç¥ããããæãå½¹ã«ç«ã¤ä¾ã§ããããããããè¦ãç®ãããã°ã©ã ã®æå³ããç®ç«ã¤ããã§ã¯ã表示ã主ä½ã«ãªã£ã¦ãã¾ã£ã¦ãããã¨ã«ãªããæ¬æ«è»¢åã§ããã§ããããå¤ãè¯ãã¿ã¤ãã©ã¤ã¿ã¼çåºåã§éãã«ãã¦ãã表示ä¸ã®é¦¬é¹¿ããããæ¹ã«ã¯æ°ãã¤ãã¾ããããè£ é£¾ãé¿ãã¾ããããä¾ãã°ãã³ã¡ã³ãã¯ç°¡æ½ã«ãããã¼ãã¤ããªãããã«ãã¾ããããè¨ãã¹ããã¨ã¯ããã°ã©ã ã®ä¸ã§ãç°¡æ½ã«ä¸è²«æ§ãæã£ã¦è¨ãã¾ãããããããã次ã«é²ã¿ã¾ãããã
å¤æ°å
ãããå¤æ°åã§ããååã§éè¦ãªã®ã¯ãé·ãã§ã¯ããã¾ãããéè¦ãªã®ã¯è¡¨ç¾ã®æ確ãã§ãããã£ãã«ä½¿ãããªããããªã°ãã¼ãã«å¤æ°ã§ããã°ãé·ãååãã¤ãã¦ãããããããã¾ãããä¾ãã°ãmaxphysaddr
ã®ããã«ãã«ã¼ãå
ã®ãã¹ã¦ã®è¡ã§ä½¿ããããããªé
åã®æ·»åã«ã¯ãi
ãããåã£ãååã¯å¿
è¦ããã¾ãããindex
ã elementnumber
ã¨ãã£ãååãã¤ããã®ã¯ãã¿ã¤ãéãå¢ããï¼ã¾ãã¯ãã¨ãã£ã¿ã®å©ããåããï¼ãã¨ã«ãªãã¾ãããè¨ç®ã®è©³ç´°ãããç®ç«ã£ã¦ãã¾ãã¾ããå¤æ°åãé常ã«é·ããªãã¨ãä½ããã¦ããã®ããããã«ãããªãã¾ããããã¯ã表示ã®åé¡ã®ä¸é¨ã§ãããã¾ãã次ã®äºã¤ã«ã¤ãã¦èãã¦ã¿ã¾ãããã
for(i=0 to 100) array[i]=0
for(elementnumber=0 to 100) array[elementnumber]=0;
å®éã®ä¾ã§ã¯ãåé¡ã¯ãã£ã¨ãã£ã¨ããéã«ã²ã©ããã¨ã«ãªãã¾ããæ·»åã¯ãã ã®è¨æ³ã§ãããã®ããã«æ±ãã¾ãããã
ãã¤ã³ã¿ãã¡ããã¨ããè¨æ³ãå¿
è¦ã§ããnp
ã "node pointer" ãæãã¦ããã¨ãããã¨ãç°¡åã«å°ãããããªå½åè¦ç´ãä¸è²«ãã¦ä½¿ã£ã¦ããã°ãnp
㯠nodepointer
ã¨åããããè¦ãããããã®ã«ãªãã¾ããããã«ã¤ãã¦ã¯æ¬¡ã®ã¨ãã»ã¤ã§è©³ããæ¸ãã¾ãã
ããã°ã©ã ã®å¯èªæ§ã«é¢ããã»ãã®å´é¢ã§ã®å ´åã¨åãããã«ãå½åã«ããã¦ãä¸è²«æ§ã¯éè¦ã§ããããå¤æ°ã« maxphysaddr
ã¨ããååãã¤ããããå種ã®å¤æ°ã« lowestaddress
ã¨ããååãã¤ãã¦ã¯ããã¾ããã
æå¾ã«ãªãã¾ãããç§ã¯æçã®é·ãã§æ大ã®æ
å ±éã®ããååãã¤ããæ®ãã¯æèããè£å®ã§ããããã«ãã¦ãã¾ããä¾ãã°ãã°ãã¼ãã«å¤æ°ã¯æ®éã使ç¨æã«ãã¾ãæèããªãã®ã§ãååã¯æ¯è¼çå
容ããããããããããªãã®ã§ããå¿
è¦ãããã¾ãããã®ãããç§ã¯ã°ãã¼ãã«å¤æ°ã«ã¯ maxphysaddr
ï¼MaximumPhysicalAddress
ã§ã¯ããã¾ããï¼ã¨ããååãã¤ãã¾ããããã¼ã«ã«ã§å®ç¾©ãã¦ä½¿ããã¤ã³ã¿ã«ã¯ NodePointer
ã§ã¯ãªã np
ã¨ããååãã¤ãã¾ããããã¯æè¦ã«ããã¨ããã大ããã§ãããæè¦ã¯æçãã«é¢ãã£ã¦ãããã®ã§ãã
ååã«å¤§æåãå ¥ãããã¨ã¯é¿ãã¦ãã¾ããæ£æ調ã®æç« ã«æ £ããç§ã®ç®ã«ã¯ã大æåã¯ä¸æ ¼å¥½ã§å¿«é©ã«èªãã¾ãããã²ã©ã表示ã®ä»æ¹ã¨åãããã«ç®éããªã®ã§ãã
ãã¤ã³ã¿ã®ä½¿ç¨
C ã¯ãã¤ã³ã¿ãä½ã§ãæããã¨ããç¹ã§å¤ãã£ã¦ãã¾ãããã¤ã³ã¿ã¯åãå³ã®éãéå ·ã§ããåãå³ã®éãéå ·ã¨ãããã®ã¯ããã¾ã使ãã¨æ¥½ããçç£çã«ãªããã¾ãããééã£ã使ãæ¹ãããã¨ã²ã©ãå·ãã¤ãã¾ãï¼ãã®è¨äºãæ¸ãæ°æ¥åã«ãç§ã¯å½«å»åã親æã«åºãã¦ãã¾ã£ãã¨ããã§ãï¼ããã¤ã³ã¿ãä¾å¤ã§ã¯ããã¾ããããã¤ã³ã¿ã¯å±éºããããä½ãæ±ããã®ã ã¨æããã¦ãããããå¦è¡çã§ã®è©å¤ã¯ããããã¾ãããããããç§ã¯ãã¤ã³ã¿ã¯å¼·åãªè¨æ³ã ã¨èãã¦ãã¾ããããã¯ããã¤ã³ã¿ã¯æçãªè¡¨ç¾ãããå½¹ã«ç«ã¤ã¨ãããã¨ã§ãã
èãã¦ã¿ã¦ãã ããããããªãã¸ã§ã¯ãã«å¯¾ãããã¤ã³ã¿ãããã¨ããããã¯ã¾ãã«ãã®ãªãã¸ã§ã¯ãã«å¯¾ããååã§ãã£ã¦ãã»ãã®ãã®ã§ã¯ããã¾ãããäºç´°ãªãã¨ã®ããã§ããã次ã®äºã¤ã®å¼ãè¦ã¦ãã ããã
np node[i]
ä¸ã¤ç®ã¯ãã¼ããæãã¦ãã¦ãäºã¤ç®ã¯åããã¼ããæãããã«è©ä¾¡ããã¾ãï¼ã¨ãããã¨ã«ãã¾ãï¼ãããããäºã¤ç®ã®å½¢å¼ã¯å¼ã§ãããã¾ãåç´ãªãã®ã§ã¯ããã¾ããã解éããã«ã¯ãnode
ãä½ããi
ãä½ãããã㦠i
㨠node
ããã®å¨ãã®ããã°ã©ã ã®ï¼ããããæè¨ããã¦ããªãï¼ã«ã¼ã«ã«ãã£ã¦é¢é£ã¥ãããã¦ããã¨ãããã¨ãç¥ãå¿
è¦ãããã¾ããå¼ã ããåãåºãã¦ã¿ãã¨ãi
ã node
ã®æå¹ãªæ·»åãªã®ããç¥ãæãããã¯ããã¾ããããã¡ãããæãè¦ç´ ãæãæ·»åãªã®ãããããã¾ããããã i
㨠j
㨠k
ãå
¨é¨ãã¼ãã®é
åã®æ·»åã ã¨ããã¨ãç°¡åã«ãã£ãããã¹ããã¦ãã¾ãã¾ãããã®å ´åãã³ã³ãã¤ã©ã¯å©ãã¦ããã¾ãããç¹ã«ããµãã«ã¼ãã³ã«æ¸¡ãã¨ãã«ã¯ééããç¯ãããããªãã¾ãããã¤ã³ã¿ã¯åç´ãªã²ã¨ã¤ã®ãã®ã§ãããé
åã¨æ·»åã¯ããããã»ããã¨ãªããã®ã§ãããã¨ãåãåããµãã«ã¼ãã³ã®ã»ãã§ä¿¡ç¨ããªãã¨ããã¾ããã
ãªãã¸ã§ã¯ãã¨ãã¦è©ä¾¡ãããå¼ã¯ãæ¬è³ªçã«ãã®ãªãã¸ã§ã¯ãã®ã¢ãã¬ã¹ããããããã«ããééãããããã®ã«ãªãã¾ãããã¤ã³ã¿ã¯ãæ£ãã使ããã¨ã§ã³ã¼ããåç´ã«ã§ãã¾ããä¾ãã°ã
parent->link[i].type
ã¨
lp->type
ã§ãã
ãã次ã®è¦ç´ ã® type ãå¿ è¦ã§ããã°ã
parent->link[++i].type
ã¨
(++lp)->type
ã«ãªãã¾ãã
i
ã¯å¤ãé²ã¿ã¾ãããå¼ã®æ®ãã¯ãã®ã¾ã¾ã§ãããã¤ã³ã¿ã®å ´åãé²ãããã®ã¯ã²ã¨ã¤ããããã¾ããã
ããã§ã表示ã®åé¡ã絡ãã§ãã¾ãããã¤ã³ã¿ã使ã£ã¦æ§é ä½ã®ä¸ãèªã¿é²ããã®ã¯ãå¼ã使ãããããã£ã¨èªã¿ããããã®ã«ãªãã¾ããã¤ã³ã¯ã®ä½¿ç¨éãæ¸ãã¾ãããã³ã³ãã¤ã©ãã³ã³ãã¥ã¼ã¿ã®å´åãæ¸ãã¾ããé¢é£ããåé¡ã¨ãã¦ããã¤ã³ã¿ã®åã¯ãã®æ£ãã使ãæ¹ã¨é¢ä¿ãã¦ããã®ã§ãé åã®æ·»åã¨éã£ã¦ã³ã³ãã¤ã«æã®ä¾¿å©ãªã¨ã©ã¼æ¤åºãå©ç¨ã§ãã¾ããã¾ãããªãã¸ã§ã¯ããæ§é ä½ã§ããã°ããã£ã¼ã«ãã¯åãæãåºãå½¹ã«ç«ã¤ã®ã§ã次ã®ãããªãã®ã¯ååã«æå³ããããã¾ãã
np->left
æ·»åã«ãã£ã¦é åã使ãå ´åãé åã¯ãã¡ãã¨é¸ãã ååãæã¤ãã¨ã«ãªããå¼ã¯é·ããªã£ã¦ãã¾ãã¾ãã
node[i].left
ããã§ãã¾ããä¾ã大ãããªãã°ä½åãªæåã¯ã©ãã©ãåä»ãªãã®ã«ãªã£ã¦ããã¾ãã
ã ãããã®å ´åãããããªãã®ã³ã¼ãã«ä¼¼ããããªè¤éãªå¼ããããããã£ã¦ããããããã¼ã¿æ§é ã®è¦ç´ ã¨ãã¦è©ä¾¡ããããªãããã¤ã³ã¿ã注ææ·±ã使ããã¨ã§ãã£ããããããã¨ãã§ãã¾ãã次ã®ã³ã¼ãã§ã
if(goleft) p->left=p->right->left; else p->right=p->left->right;
ãã p
ã®ä»£ããã«è¤åå¼ã使ã£ã¦ãããã©ããªè¦ãç®ã«ãªããèãã¦ã¿ã¦ãã ãããè¨ç®ã®æ¬è³ªãæãåºãã«ã¯ãæã«ã¯ä¸æå¤æ°ï¼ããã§ã¯ p
ï¼ããã¯ãã使ããã¨ãå½¹ã«ç«ã¡ã¾ãã
ããã·ã¼ã¸ã£å
ããã·ã¼ã¸ã£åã¯ããããä½ããããã表ãã¦ããã¹ãã§ããé¢æ°åã¯ããããä½ãè¿ããã表ãã¦ããã¹ãã§ããé¢æ°ã¯å¼ã®ä¸ã§ä½¿ããããã®ã§ãif
ã®ãããªãã®ã®ä¸ã§ãã使ããã¾ãããã®ãããé©åã«èªããããã«ãªã£ã¦ããå¿
è¦ãããã¾ãã
if(checksize(x))
ã¯ä¸è¦ªåã§ããchecksize
ãã¨ã©ã¼ã®ã¨ãã« true ãè¿ãã®ããã¨ã©ã¼ã§ãªãã¨ãã« true ãè¿ãã®ããæ¨æ¸¬ã§ããªãããã§ããããã«å¯¾ãã¦ã
if(validsize(x))
ã¯ãã®ç¹ãæ確ã«ãã¦ããã®ã§ãå°æ¥ãã®ã«ã¼ãã³ã使ãã¨ãã«ééããèµ·ããã«ããã§ãããã
ã³ã¡ã³ã
ããã¯ã»ã³ã¹ã¨å¤æåãå¿ è¦ã¨ãªãé£ããåé¡ã§ããç§ã¯ãããã¤ãã®çç±ãããã³ã¡ã³ãããã¾ãæ¸ããªãããã«ãã¦ãã¾ããã²ã¨ã¤ã¯ãããã³ã¼ããæ確ã§ãããååãå¤æ°åã使ã£ã¦ãããªããã³ã¼ãèªèº«ã説æã«ãªã£ã¦ããã¯ãã ããã§ããããã«ãã³ã¡ã³ãã¯ã³ã³ãã¤ã©ã«ãã§ãã¯ãããªãã®ã§ãæ£ããã¨ããä¿è¨¼ããªãããã§ããç¹ã«ãã³ã¼ããå¤æ´ããããã¨ã¯ããã§ãããã¹ãªã¼ãã£ã³ã°ãªã³ã¡ã³ãã¯é常ã«ç´ãããããã®ã§ããæå¾ã«ã表示ã®åé¡ã§ããã³ã¡ã³ãã¯ã³ã¼ãããã¡ããã¡ãã«ãã¦ãã¾ãã¾ãã
ããããç§ãæã ã¯ã³ã¡ã³ããæ¸ãã¾ããã»ã¨ãã©ã®å ´åããã®æ¬¡ã«ç¶ããã¨ã®èª¬æã¨ãã¦ä½¿ã£ã¦ãã¾ããä¾ãæããã¨ãã°ãã¼ãã«å¤æ°ã¨åã®èª¬æï¼ãã®å ´åã ãã¯ã大ããªããã°ã©ã ã§ã¯å¿ ãã³ã¡ã³ããæ¸ãã¾ãï¼ããã¾ãè¦ãªãããã·ã¼ã¸ã£ãé常ã«éè¦ãªããã·ã¼ã¸ã£ã®ç´¹ä»ã大ããªè¨ç®ã»ã¯ã·ã§ã³ã®åºåããªã©ã§ãã
æåãªæªãã³ã¡ã³ãã¨ãããã®ãããã¾ãã
i=i+1; /* i ã« 1 ã足ã */
ãã®ãã£ã¨æªãããæ¹ãããã¾ãã
/********************************** * * * i ã« 1 ã足ã * * * **********************************/ i=i+1;
ç¬ãã®ã¯æ©ãã§ãããç¬ãã®ã¯ãå®çæ´»ã§åºä¼ã£ã¦ããã§ãé ãããã¾ããã
ã³ã¡ã³ãã§ã¯ããã£ããã表示ãé¿ãã¾ããããä¸å¿ã¨ãªããã¼ã¿æ§é ã®å®£è¨ã®ãããªéè¦ãªã¨ããã¯ä¾å¤ã¨ãã¦ãããã§ããããï¼ãã¼ã¿ã«å¯¾ããã³ã¡ã³ãã¯ãæ®éã¢ã«ã´ãªãºã ã«å¯¾ããã³ã¡ã³ãããããã£ã¨å½¹ã«ç«ã¤ãã®ã§ãï¼ãã³ã¡ã³ãã®å¤§ããªå¡ãé¿ãã¾ããããåºæ¬çã«ãã³ã¡ã³ããé¿ãã¾ããããããã³ã¡ã³ãããªãã¨ç解ã§ããªããããªããç解ãããããªãããã«æ¸ãç´ããã»ããããã§ããããããã§ã次ã®åé¡ãåºã¦ãã¾ãã
è¤éã
ã»ã¨ãã©ã®ããã°ã©ã ã¯è¤éããã¾ããã¤ã¾ããåé¡ãå¹ççã«è§£ãã®ã«å¿ è¦ãªä»¥ä¸ã«è¤éã ã¨ãããã¨ã§ãããªãã§ãããããå¤ãã®å ´åãããã¯è¨è¨ã®æªããåå ã§ããããã®åé¡ã¯å¤§ããããã®ã§ããã§ã¯é£ã°ãã¾ããããããããã°ã©ã ã¯ç´°ããã¬ãã«ã§ãè¤éããããã¨ãå¤ããã®ã§ããã®ãã¨ã«ã¤ãã¦ã¯ããã§æ¸ããã¨ãã§ãã¾ãã
ã«ã¼ã«1 ããã°ã©ã ãã©ãã§æéã使ããã¯ãããã¾ãããããã«ããã¯ã¯é©ããããªå ´æã§èµ·ããã®ã§ãããã«ããã¯ã®å ´æã証æã§ããã®ã§ãªããã°ãé©å½ãªæ¨æ¸¬ã§é«éåããã¯ãå ¥ããã®ã¯ããã¾ãããã
ã«ã¼ã«2 è¨æ¸¬ãã¾ããããè¨æ¸¬ãªãã«é度ã®ãã¥ã¼ãã³ã°ãããªãã§ãã ãããè¨æ¸¬ããå ´åã§ããã³ã¼ãã®ä¸ç®æãã»ãã®å ´æã«æ¯ã¹ã¦å§åçã«æéãããã£ã¦ããã®ã§ãªããã°ããã¥ã¼ãã³ã°ã¯ããã¾ãããã
ã«ã¼ã«3 ãã£ãããã¢ã«ã´ãªãºã ã¯ãn ãå°ããã¨ãã«ã¯é ããã®ã§ããããã¦ãn ã¯æ®éå°ãããã®ã§ãããã£ãããã¢ã«ã´ãªãºã ã¯å¤§ããªå®æ°é ãæã£ã¦ãããã®ã§ããn ããã大ããªå¤ã«ãªãã¨ããã£ã¦ããã®ã§ãªããã°ããã£ããããã¨ãããã®ã¯ããã¾ãããï¼n ã大ãããªãå ´åã§ããã¾ãã«ã¼ã«2 ã使ãã¾ãããï¼ãä¾ãã°ãæ¥å¸¸æ¥åã®åé¡ã§ã¯ãäºåæ¨ã¯å¸¸ã«ã¹ãã¬ã¼æ¨ããéããã®ã§ãã
ã«ã¼ã«4 ãã£ãããã¢ã«ã´ãªãºã ã¯åç´ãªã¢ã«ã´ãªãºã ããããã°ãèµ·ããããããå®è£ ãé£ãããã®ã§ããåç´ãªã¢ã«ã´ãªãºã ã¨åç´ãªãã¼ã¿æ§é ã使ãã¾ãããã
ã»ã¨ãã©ã®å®ç¨çãªããã°ã©ã ã§ã¯ã次ã«æãããªã¹ãã®ãã¼ã¿æ§é ãããã°ååã§ãã
- é å
- é£çµãªã¹ã
- ããã·ã¥ãã¼ãã«
- äºåæ¨
ãã¡ãããããããçµã¿åããã¦è¤åãã¼ã¿æ§é ãä½ãè¦æã¯å¿ è¦ã§ããä¾ãã°ãã·ã³ãã«ãã¼ãã«ã¯æåã®é åã®é£çµãªã¹ããå«ãããã·ã¥ãã¼ãã«ã¨ãã¦å®è£ ãããããããã¾ããã
ã«ã¼ã«5 éè¦ãªã®ã¯ãã¼ã¿ã§ããããæ£ãããã¼ã¿æ§é ãé¸ã³ãç©äºããã¾ãã¾ã¨ããã°ãã¢ã«ã´ãªãºã ã¯ããã¦ãèªæãªãã®ã«ãªãã¾ããããã°ã©ã ã®ä¸å¿ã¯ãã¢ã«ã´ãªãºã ã§ã¯ãªãããã¼ã¿æ§é ã§ããï¼è©³ããã¯ã人æã®ç¥è©±ããåç §ãã¦ãã ããï¼
ã«ã¼ã«6 ã«ã¼ã«6ã¯ããã¾ããã
ãã¼ã¿ã§ããã°ã©ã ãã
ã¢ã«ã´ãªãºã ããã¢ã«ã´ãªãºã ã®ç´°ããã¨ããã¯ãããããã® if
æã®ãããªãã®ã§æ¸ããããããã¼ã¿ã¨ãã¦æ¸ããã»ãããå¹çããå¼·åã«è¨å·åãããã¨ãã§ãããã¨ãããããã¾ãããã®çç±ã¯ãæå
ã®ä»äºã®è¤éããç¬ç«ããç´°ããé¨åã®çµã¿åããã«ãããã®ã§ããã°ãè¨å·åã§ããããã§ããå
¸åçãªä¾ã¨ãã¦ã¯ããã¼ã¸ã³ã°ãã¼ãã«ã¨ãããã®ãããã¾ããããã°ã©ãã³ã°è¨èªã®ææ³ããå®åã®ããªãåç´ãªã³ã¼ãã«ãã£ã¦è§£éã§ããå½¢ã«è¨å·åãããã®ã§ãããã®æã®ããæ¹ã¨ãã¦ã¯æéç¶æ
æ©æ¢°ãç¹ã«æè»ã«ä½¿ãã¾ãããä½ããã®æ½è±¡çãªå
¥åãããã¼ã¸ã³ã°ããã¦ä½ããã®ç¬ç«ãããã¢ã¯ã·ã§ã³ãåã«ãããããªããã°ã©ã ã§ããã°ãã©ããªãã®ã§ãã£ã¦ããã¼ã¿é§åã¢ã«ã´ãªãºã ã«ãããã¨ã§ããçµæãå¾ãããã§ãããã
ãã®ãããªè¨è¨ã®ããããæãèå³æ·±ãå´é¢ã¯ããã¼ãã«ãã»ãã®ããã°ã©ã ã«ãã£ã¦çæããããã¨ãããã¨ãããã¨ã§ããå ¸åçãªä¾ã§ããã¨ããã¼ã¶ã¸ã§ãã¬ã¼ã¿ãããã¾ããããå°ã身è¿ãªä¾ã¨ãã¦ã¯ãOSãI/Oãªã¯ã¨ã¹ããé©åãªããã¤ã¹ãã©ã¤ãã«å²ãå½ã¦ããã¼ãã«ã«ãã£ã¦åãã¦ããå ´åããã·ã³ã«æ¥ç¶ãããããã¤ã¹ã«ã¤ãã¦ã®è¨è¿°ãèªã¿è¾¼ãã§å¯¾å¿ãããã¼ãã«ã表示ãããããªããã°ã©ã ã§ãè¨å®ãã§ããã§ãããã
ãã¼ã¿é§åããã°ã©ã ãï¼å°ãªãã¨ãåå¿è ã®éã§ï¼ä¸è¬çã§ãªãçç±ã®ã²ã¨ã¤ã¯ãPascalã®ç¬è£ã§ããPascalã¯ããã®ä½è åæ§ãã³ã¼ãã¨ãã¼ã¿ãåå²ãããã¨ãåºãä¿¡ãã¦ãã¾ãããã®ãããï¼å°ãªãã¨ãå ã®å½¢ã§ã¯ï¼åæåããããã¼ã¿ãä½ããã¨ãã§ãã¾ãããããã¯ãããã°ã©ã å èµæ¹å¼ã®ååãå®ç¾©ãããã¥ã¼ãªã³ã°ããã©ã³ã»ãã¤ãã³ã®çè«ã«çã£åããå§å©ã売ã£ã¦ãã¾ããã³ã¼ãã¨ãã¼ã¿ã¯åããã®ã§ããå°ãªãã¨ããåãã«ãããã¨ãã§ãã¾ããããã§ãªããã°ãã³ã³ãã¤ã©ãã©ããã¦åãã®ã説æã§ããªãã§ããããï¼é¢æ°åè¨èªã¯I/Oã«é¢ãã¦åããããªåé¡ãæ±ãã¦ãã¾ãï¼
é¢æ°ãã¤ã³ã¿
Pascalã®ç¬è£ã®çµæã«ã¯ãåå¿è ãé¢æ°ãã¤ã³ã¿ã使ããªãã¨ãããã¨ãããã¾ãï¼Pascal ã§ã¯é¢æ°ãå¤ã«æã¤å¤æ°ã使ãã¾ããï¼ãè¤éããè¨å·åããããã«é¢æ°ãã¤ã³ã¿ã使ããã¨ã«ã¯ãããã¤ãã®é¢ç½ãæ§è³ªãããã¾ãã
è¤éãã®ä¸é¨ã¯ããã¤ã³ã¿ã®æãã«ã¼ãã³ã«æ¸¡ããã¾ããã«ã¼ãã³ã¯ãåãããã«å¼ã³åºãããã«ã¼ãã³ã»ããã®ã²ã¨ã¤ã¨ãªãã®ã§ãä½ãããã®æ¨æºãããã³ã«ã«å¾ãå¿ è¦ãããã¾ããããããããããéè¦ãªã®ã¯ãã«ã¼ãã³ãèªåã®è²¬ä»»ç¯å²ã®ãã¨ããããªãã¨ãããã¨ã§ããè¤éãã¯åæ£ããããã¨ã«ãªãã¾ãã
ãã®ãããã³ã«ã¨ããèãæ¹ã¯ãåããããªä½¿ããæ¹ãããé¢æ°ã¯åããããªãµãã¾ããããªããã°ãªããªãã¨ãããã®ã§ãããã®ãã¨ããããã¥ã¡ã³ãã®è¨è¿°ããã¹ããããã°ã©ã ã®çºå±ãããããããã¦ãã¾ããããã«ã¯ãããã°ã©ã ããããã¯ã¼ã¯è¶ãã«åãããã¨ãããããããªãã¾ãããããã³ã«ã¯ããªã¢ã¼ãããã·ã¼ã¸ã£ã³ã¼ã«ã¨ãã¦ãè¨å·åã§ããã®ã§ãã
ç§ã®ä¸»å¼µã¯ããªãã¸ã§ã¯ãæåããã°ã©ãã³ã°ã®æ ¸å¿ã¨ãªããã®ã¯ãé¢æ°ãã¤ã³ã¿ãæ確ã«ä½¿ããã¨ã ã¨ãããã®ã§ãããã¼ã¿ã«ã¤ãã¦å®è¡ãããæä½ã»ãããããããããã®æä½ã«å¯¾ãã¦é©ç¨ããããã¼ã¿åã®ã»ããããããªããããã°ã©ã ãã¾ã¨ããä¸çªç°¡åãªæ¹æ³ã¯ãããããã®åã«å¯¾ãã¦é¢æ°ãã¤ã³ã¿ã®ã°ã«ã¼ãã使ãã¨ãããã®ã§ããããã¯ãä¸è¨ã§è¨ãã¨ãã¯ã©ã¹ã¨ã¡ã½ãããå®ç¾©ããã¨ãããã¨ã§ãããã¡ããããªãã¸ã§ã¯ãæåè¨èªã«ã¯ãã以ä¸ã®ãã®ãããã¾ããããããªæ§æãæ´¾çåãªã©ãããããæ¦å¿µçã«ã¯ãã»ã¨ãã©å¤ããã¨ããã¯ããã¾ããã
ãã¼ã¿é§åããã°ã©ã ã¨é¢æ°ãã¤ã³ã¿ãçµã¿åãããã¨ãã³ã£ããããã»ã©è¡¨ç¾åã®ããæ¸ãæ¹ãã§ããããã«ãªããç§ã®çµé¨ã§ã¯ãæå¤ãªåã³ãããããã¦ããããã¨ãããããã¾ãããç¹å¥ãªãªãã¸ã§ã¯ãæåè¨èªãªãã§ããä½è¨ãªæéãªãã§ãªãã¸ã§ã¯ãæåã®ããã¨ããã®90%ãæã«å ¥ãããã¨ãã§ããçµæã«ã¤ãã¦ãèªåã§ã³ã³ããã¼ã«ãããããªãã¾ããããã»ã©ãå§ãã§ããå®è£ ã¹ã¿ã¤ã«ã¯ããã¾ããããã®æ¹æ³ã§æ§ç¯ãã¦ããããã°ã©ã ã¯ãããªãã®éçºãéãã¦ããã¾ãçãæ®ã£ã¦ãã¾ãããã£ã¨ãããããæ¹ã®å ´åãããããã£ã¨ããçµæã§ãããã£ã¨ããã®ææ³ã«æ±ããããè¦å¾ã¯ãé·ãç®ã§è¦ãã¨å²ã«åãã¨ãããã¨ã§ãããã
ã¤ã³ã¯ã«ã¼ããã¡ã¤ã«
åç´ãªã«ã¼ã«ã§ããã¤ã³ã¯ã«ã¼ããã¡ã¤ã«ã¯ã¤ã³ã¯ã«ã¼ããã¡ã¤ã«ã決ãã¦ã¤ã³ã¯ã«ã¼ããã¦ã¯ããã¾ããããã®ä»£ããã«ãã©ã®ãã¡ã¤ã«ãå
ã«ã¤ã³ã¯ã«ã¼ãããã¹ãããï¼ã³ã¡ã³ãã§ãã¾ãã¯æé»çã«ï¼è¨æããã¦ããã°ãã©ã®ãã¡ã¤ã«ãã¤ã³ã¯ã«ã¼ãããã¹ããã¨ããåé¡ã¯ã¦ã¼ã¶ï¼ããã°ã©ãï¼ã«æ¼ãã¤ãããã¾ãããããæå³ã§ã¯æ±ãããããçµã¿ç«ã¦æ¹ã«ãã£ã¦å¤éã¤ã³ã¯ã«ã¼ããé¿ãããã¨ãã§ããããã«ãªãã¾ããå¤éã¤ã³ã¯ã«ã¼ãã¯ã·ã¹ãã ããã°ã©ãã³ã°ã®çã§ããã²ã¨ã¤ã® C ã®ã½ã¼ã¹ãã¡ã¤ã«ãã³ã³ãã¤ã«ããã®ã«ã5 å以ä¸ãã¤ã³ã¯ã«ã¼ãããããã¡ã¤ã«ããããã¨ã¯çãããã¨ã§ã¯ããã¾ããããã®é¢ããè¨ãã¨ãUnix ã® /usr/include/sys
ã¯ã²ã©ããã®ã§ãã
#ifdef
ã使ã£ã¦ãã¡ã¤ã«ã 2 åèªã¾ããªãããã«ããå°æå
ã®ãã¯ããã¯ãããã¾ãããå®éã«ã¯æ£ããéç¨ãããªããã®ã§ãã#ifdef
ã¯ãã¡ã¤ã«èªèº«ã®ä¸ã«ãããã¤ã³ã¯ã«ã¼ãããå´ã«ããã®ã§ã¯ããã¾ãããçµæã¨ãã¦ãä½åè¡ãã®ä¸è¦ãªã³ã¼ããåå¥è§£æå¨ã«æ¸¡ããããã¨ã«ãªã£ã¦ãã¾ãã¾ããããã¯ãï¼è¯ãã³ã³ãã¤ã©ã®å ´åï¼æãè² è·ã®é«ããã§ã¼ãºã«ãªã£ã¦ãã¾ãã¾ãã
åç´ãªã«ã¼ã«ã«å¾ãã¾ãããã