ãã®æ¥èšã«ã¯å®çšçãªå©ç¹ã¯ãªãããã¥ãŒããªã¢ã«ã§ã¯ãããŸããããç§ã¯ãããèªãããšã«éåžžã«èå³ããããŸãããããªãããã®ç©èªã奜ãã«ãªãããšãé¡ã£ãŠããŸã:)
40æ¥ã§8ccãšåŒã°ããCã³ã³ãã€ã©ãäœæããŸããã ããã¯åœæç§ãæžããæ¥èšã§ãã ã³ãŒããšãã®å±¥æŽã¯GitHubã§è¡šç€ºã§ããŸãã
8æ¥ç®
ã³ã³ãã€ã©ãæžããŠããŸãã çŽ1000è¡ã®ã³ãŒããèšè¿°ããåŸãåäœãéå§ããŸããã ãã§ã«æ©èœããããã€ãã®äŸã次ã«ç€ºããŸãã
int a = 1; a + 2; // => 3 int a = 61; int *b = &a; *b; // => 61
é åã¯ãã€ã³ã¿ãŒã«æ£ããå€æãããããã以äžã®ã³ãŒããæ©èœããŸãã é¢æ°åŒã³åºãããµããŒããããŠããŸãã
char *c = "ab" + 1; printf("%c", *c); // => b
ãããå®è£ ããã®ã¯é£ãããããŸããã§ããã ç§ã¯ãããäºåºŠç®ã«ããŠããŸãã é åãšãã€ã³ã¿ãŒãããé©åã«åŠçããæ¹æ³ãåŠã³ãŸããã
15æ¥ç®
ã³ã³ãã€ã©ãŒã®å®è£ ã«ã¯é·ãéã®ãããããé©ãã»ã©ããŸãæ©èœããŠããŸãã èªæã§ã¯ãªãããã°ã©ã ãããšãã°ãã ã¯ã8人ã®å¥³çã®è§£æ±ºèª²é¡ã§ãã ãã³ã³ãã€ã«ãããŠèµ·åãããŸãã
ãã¡ããã圌ã«ã¯å€ãã®æ©èœããããŸããã ãããã®ãµã³ãã«ããã°ã©ã ã¯ã䜿çšããªãããã«éžæãããŠããŸãã
å®è£ ã¯éåžžã«ç°¡åã§ãã ã¬ãžã¹ã¿ã®å²ãåœãŠãããããŸããã
ãœãŒã¹ããã°ã©ã ãã¹ã¿ãã¯ãã·ã³ã®ã³ãŒãã«ã³ã³ãã€ã«ããã¹ã¿ãã¯ãã·ã³ã¯ã·ã¹ãã ã¹ã¿ãã¯ãã¹ã¿ãã¯ãšããŠäœ¿çšããŸãã åæäœã«ã¯ã¡ã¢ãªã¢ã¯ã»ã¹ãå¿ èŠã§ãã ããããä»ã®ãšãããããã¯ç§ã«åã£ãŠããŸãã
æåãã³ã³ãã€ã©ã¯çŽ20è¡ã«åãŸããã³ã³ãã€ã©ãå®è¡ã§ããã®ã¯ãæšæºå ¥åããæŽæ°å€ãèªã¿åããæŽæ°ãè¿ãããšãããã«çµäºããããã°ã©ã ãå®è¡ããããšã ãã§ããã
çŸåšãçŽ2000è¡ãå«ãŸããŠããŸãã gitãèŠããšã次ã®ããã«éçºãããŠããããã§ãã
- ã+ããšã-ããè¿œå ããŸãã
- 解æãšã³ãŒãçæã®ãã§ãŒãºãåé¢ãããŠããŸã
- ã*ããšã/ããè¿œå
- è¿œå ãããå€æ°ïŒæé»çã«intåãæå³ããïŒ
- é¢æ°åŒã³åºããè¿œå ãããŸãã
- è¿œå ãããè¡
- åå¥ã®ããŒã¯ãã€ã¶ãŒãšæ§æ解æ
- åºæ¬å宣èšã®ãµããŒã
- è¿œå ããããã€ã³ã¿ãŒãšé å
- é ååæååŒã®ãµããŒã
- ãifããè¿œå
- ãµããŒããããé¢æ°å®£èš
- è¿œå ããã³è¿åŽ
- ãµããŒãããããã€ã³ã¿ãŒå²ãåœãŠ
- ã==ããè¿œå
- é åã®ã€ã³ããã¯ã¹ä»ããšãã€ã³ã¿ãŒæŒç®ãè¿œå ãããŸãã
- ã++ããã-ãããïŒããè¿œå
17æ¥ç®
æ§é ã®å®è£ ã«æåããŸããã æ§é ã¯ãè€æ°ã®æ©æ¢°èªãå æã§ãããªããžã§ã¯ãã§ãã å®è£ ã¯ããªããã£ãåãããé£ããã§ãããæã£ãããç°¡åã§ããã
æ£åžžã«æ©èœããããã§ãã æ§é ãå«ãæ§é ãå®çŸ©ã§ããŸãã æ§é äœãžã®ãã€ã³ã¿ãŒãå®çŸ©ãããããéåç §ã§ããŸãã é åããã³æ§é ã®é åãå«ãæ§é ãæ©èœããŸãã çè«çã«ã¯ã³ãŒããæ©èœããã¯ãã§ããããšã¯ãã§ã«ç¥ã£ãŠããŸãããããã®ãããªå°é£ãªã±ãŒã¹ã§ãã£ãŠããå®éã«æ©èœãããšãã¯æºè¶³ããŠããŸããã
ãã ãããã®ã³ãŒããæ£ããæ©èœããŠããçç±ãå®å šã«ç解ããŠãããšã¯æããŸããã ååž°çãªæ§è³ªã®ãããå°ãäžæè°ãªæããããŸãã
æ§é äœãé¢æ°ã«æž¡ãããšã¯ã§ããŸããã x86ã®åŒã³åºãèŠçŽã§ã¯ãæ§é äœãã¹ã¿ãã¯ã«ã³ããŒããããã®æ§é äœãžã®ãã€ã³ã¿ãŒãé¢æ°ã«æž¡ãããŸãã ããããx86-64ã§ã¯ãæ§é ãããã€ãã®ããŒã¿ã«åå²ããããããã¬ãžã¹ã¿ã«æž¡ãå¿ èŠããããŸãã é£ããã®ã§ãä»ã®ãšãã延æããŸãã æ§é äœãå€ã§æž¡ãããšã¯ãæ§é äœã«ãã€ã³ã¿ãŒãæž¡ãããšãããå¿ èŠæ§ãäœããªããŸãã
18æ¥ç®
é¢é£ä»ããå®è£ ããæ¹ãç°¡åã ã£ãã®ã¯ã ããã¯ããã¹ãŠã®ãã£ãŒã«ããåããªãã»ãããæã€æ§é ã®åãªãå€åœ¢ã§ãã ã->ãæŒç®åãå®è£ ãããŠããŸãã ãã®ããã«ç°¡åã
æµ®åå°æ°ç¹ãµããŒãã®ç·šæã¯å°é£ã§ããã intãšfloatéã®æé»çãªåå€æã¯æ©èœããŠããããã«èŠããŸãããæµ®åå°æ°ç¹æ°ãé¢æ°ã«æž¡ãããšã¯ã§ããŸããã ç§ã®ã³ã³ãã€ã©ã§ã¯ããã¹ãŠã®é¢æ°ãã©ã¡ãŒã¿ãŒãæåã«ã¹ã¿ãã¯ã«ããã·ã¥ããã次ã«x86-64åŒã³åºãèŠçŽã§æå®ãããé åºã§ã¬ãžã¹ã¿ãŒã«æžã蟌ãŸããŸãã ãããããã®ããã»ã¹ã«ã¯æããã«ãã°ããããŸãã ã¡ã¢ãªã¢ã¯ã»ã¹ãšã©ãŒïŒSIGSEGVïŒãè¿ããŸãã ã³ã³ãã€ã©ãŒã¯ã¢ã»ã³ãã©ãŒãèªã¿åãçšã«æé©åããªããããã¢ã»ã³ãã©ãŒã®åºåãèæ ®ãããšãããã°ãå°é£ã§ãã ç§ã¯äžæ¥ã§ãããçµããããšãã§ãããšæã£ãããç§ã¯ééã£ãŠããã
19æ¥ç®
x86-64åŒã³åºãèŠçŽã«åŸã£ãŠãã¹ã¿ãã¯ãã¬ãŒã ã16ãã€ãã«æããå¿ èŠãããããšãå¿ããŠãããããæéãç¡é§ã«ããŸããã è€æ°ã®æµ®åå°æ°ç¹æ°ãæž¡ããšãprintfïŒïŒãSEGVã§ã¯ã©ãã·ã¥ããããšãããããŸããã ãããåçŸã§ããæ¡ä»¶ãèŠã€ããããšããŸããã ã¹ã¿ãã¯ãã¬ãŒã ã®äœçœ®ãéèŠã§ããããšãå€æãããããABI x86-64ã®èŠä»¶ã«ã€ããŠèããããã«ãªããŸããã
ç§ã¯ããããŸã£ããæ°ã«ããŸããã§ããã®ã§ãã¹ã¿ãã¯ãã¬ãŒã ã¯8ãã€ãã ãã¢ã©ã€ã¡ã³ããããŸããããprintïŒïŒã¯æŽæ°ã®ã¿ãåãå ¥ãããŸã§æå¥ãèšããŸããã§ããã ãã®åé¡ã¯ãCALLåœä»€ãåŒã³åºãåã«ã¹ã¿ãã¯ãã¬ãŒã ã調æŽããããšã§ç°¡åã«ä¿®æ£ã§ããŸãã ãã ããã³ãŒããèšè¿°ããåã«ä»æ§ã泚ææ·±ãèªãã§ããªãéãããã®ãããªåé¡ãåé¿ããããšã¯ã§ããŸããã
20æ¥ç®
ã³ã³ãã€ã©ã³ãŒãã®ã€ã³ãã³ãã2ãã4ã«å€æŽããŸããã2ã€ã®ç©ºçœã€ã³ãã³ãã¯ãGoogleã§ã®äœæ¥ã§äœ¿çšãããããã2ã€ã®äœ¿çšã«æ £ããŠããŸãã ããããäœããã®çç±ã§ã4ã¹ããŒã¹ã®ã€ã³ãã³ãã¯ãçŸãããªãŒãã³ãœãŒã¹ããã°ã©ã ãã«ããé©ããŠãããšæããŸãã
ããã«éèŠãªå€æŽããããŸãã ãã¹ããã·ã§ã«ã¹ã¯ãªããããCã«æžãçŽããŸããããã®å€æŽã®åã«ãGCCã«ãã£ãŠã³ã³ãã€ã«ãããã·ã§ã«ã¹ã¯ãªããã«ãã£ãŠå®è¡ãããmainïŒïŒã«é¢é£ä»ããããã³ã³ãã€ã©ãŒã«ãã£ãŠã³ã³ãã€ã«ãããåãã¹ãé¢æ°ã é ãã®ã§ ãã¹ãããšã«å€ãã®ããã»ã¹ãçæããŸããã ãããžã§ã¯ããå§ãããšããç§ã«ã¯éžæè¢ããããŸããã§ããã ç§ã®ã³ã³ãã€ã©ã«ã¯å€ãã®æ©èœããããŸããã§ããã ããšãã°ãæ¯èŒæŒç®åããªããããçµæãæåŸ å€ãšæ¯èŒã§ããŸããã§ããã ããã§ããã¹ãã³ãŒããã³ã³ãã€ã«ã§ããã»ã©åŒ·åã«ãªããŸããã ããã§ãããããããéãããããã«æžãçŽããŸããã
ãŸããlongãdoubleãªã©ã®å€§ããªåãå®è£ ããŸããã ãããã®æ©èœãããã«å®è£ ã§ããã®ã§ãã³ãŒããæžãã®ã¯æ¥œããã£ãã§ãã
21æ¥ç®
ç§ã¯1æ¥ã§Cããªããã»ããµã®å®è£ ãã»ãŒå®äºããŸããã ããã¯å®éã«ã¯ãã³ã³ãã€ã©ãŒãäœæããããã®ä»¥åã®è©Šã¿ããã®ç§»æ€ã§ãã
Cããªããã»ããµã®å®è£ ã¯ç°¡åãªäœæ¥ã§ã¯ãããŸããã
ããã¯ãä»æ§ã§å®çŸ©ãããŠããCæšæºã®äžéšã§ãã ããããä»æ§ã¯èªå·±å®è£ ã«åœ¹ç«ã€ã«ã¯å°ãªãããŸãã ãã®ä»æ§ã«ã¯ãæ¡åŒµããã圢åŒã®ããã€ãã®ãã¯ããå«ãŸããŠããŸãããã¢ã«ãŽãªãºã èªäœã«ã€ããŠã¯ã»ãšãã©èª¬æããŠããŸããã 圌女ã¯åœŒã®æåŸ ãããè¡åã®è©³çŽ°ãã説æããŠããªããšæããŸãã äžè¬ã«ãããã¯æå®äžè¶³ã§ãã
ç§ã®ç¥ãéãã ãã®ããã°ã®PDFã¯ãCèšèªããªããã»ããµã®å®è£ æ¹æ³ã«é¢ããå¯äžãã€æè¯ã®ãªãœãŒã¹ã§ãããã®ããã¥ã¡ã³ãã§èª¬æãããŠããã¢ã«ãŽãªãºã ïŒDave Prosserã¢ã«ãŽãªãºã ïŒã¯ããã¯ãã®ç¡éã®æ¡åŒµãåé¿ããªãããã§ããã ãå€ãã®ããŒã¯ã³ãå±éããããšããŸãã åããŒã¯ã³ã«ã¯ç¬èªã®å±éå±¥æŽããããããåããã¯ãã«ãã£ãŠããŒã¯ã³ãè€æ°åå±éãããããšã¯ãããŸããã
Cããªããã»ããµèªäœã¯ç¬ç«ããèšèªã§ãã å€ãã®æ©èœããããããã©ã³ã®Cããã°ã©ããŒã ãããããããç解ããŠããŸãã
22æ¥ç®
ã³ã³ãã€ã©ã«ã·ã¹ãã ããããŒãèªã¿åãããããšãããããïŒincludeãç解ã§ããããã«ãªããŸããã è©ŠããŠããéã«ãå€ãã®ãšã©ãŒãçºçããŸããã ããã«ãããç§ã®ããªããã»ããµã«ã¯ãŸã å€ãã®æ©èœãæ¬ ããŠããããšãæããã«ãªããŸãããããšãã°ãïŒifã§ãã䜿çšã§ããªãæŒç®åã§ãã ãã以å€ã«ãå€ãã®ãã°ããããŸãã èŠã€ãããããã«ä¿®æ£ããŸããã
ã·ã¹ãã ããããŒãã¡ã€ã«ã¯å€§ãããæ··ä¹±ãæããŸãã ãããã«ã¯ãenumãtypedefãªã©ãã³ã³ãã€ã©ããã®å€ãã®é¢æ°ãå¿ èŠã§ãã ç§ã¯ããããäžã€ãã€å®è£ ããŸããããæã è§ãåããŸããã stdio.hãèªã¿èŸŒãããšããŠããŸãã ç§ã¯ãããã©ããããããããããããªãã
ã³ã³ãã€ã©ã¯çŸåš4000è¡ã§æ§æãããŠããŸãã å°ããªLCCã³ã³ãã€ã©ã«ã¯12,000è¡ãå«ãŸããŠããŸãã ãããã¬ã€ããšããŠäœ¿çšãããšãç§ã®ã³ã³ãã€ã©ã¯ãŸããªãæ¬ç©ã®Cã³ã³ãã€ã©ã®ããã«åäœã§ããããã«ãªããšæããŸãã
ä»æ¥500è¡ã®ã³ãŒããæžããããšã«é©ããŸããã ç§ã¯12æéã¹ããªãŒã ã§äœæ¥ã§ããŸãããéå¹çã«ãªãå¯èœæ§ããããŸãã æ°ã¥ããªããã¡ã«ç²ããŠããŸããŸãã ãããã«ãããç§ã¯èªç±æéã®å€ã人ã§ããããšãèªããªããã°ãªããŸããã
24æ¥ç®
äœãä¿®æ£ããã®ãèŠããŠããŸããããstdio.hã¯æ¥ç¶ã§ããŸãã ããã¯ãããããŒãã¡ã€ã«ã§å®çŸ©ãããŠããé¢æ°ã®çš®é¡ãæ£ããåŠçãããããã«ãªã£ããããéåžžã«ã¯ãŒã«ã§ãã
ã³ã³ãã€ã©ã®å®è£ ã«äœ¿çšããã¹ããŒã ã¯ãèšèªã®å°ããªãµãã»ããçšã®ã³ã³ãã€ã©ãäœæãããããå®éã®Cèšèªã«éçºããããšãæå³ããŸããæè¿ãŸã§ãç§ã¯å®å šã«ç解ããŠããªãé¢æ°ãå®è£ ããããšããŸããã§ããã å¿ èŠãªã ãã³ãŒããèšè¿°ããæ®ãã¯ãã®ãŸãŸã«ããŠããããšãã§ããŸãã 楜ããã£ãã
ããããŒã·ã¹ãã ãªã©ã®å€éšã®ãã®ã¯ãå€ãã®åé¡ãåŒãèµ·ãããŠããŸãã ãå®éã®ãCã³ã³ãã€ã©ã«æåŸ ããããã¹ãŠã®æ©èœãå®è£ ããå¿ èŠããããŸãããstdio.hãèªãããã«å€ãã®æ±ããããã³ã°ãè¡ããŸããã ããšãã°ããconstãããŒã¯ã³ã®ãã¹ãŠã®åºçŸãç¡èŠããããã¯ãå®è£ ããŸããã ããã¯ç§ãæ··ä¹±ãããŸãã
æåããæ£ããæ¹æ³ã§ãããããªãã®ã¯ãªãã§ããããã ããã¯é¢çœããªããšæããŸãã å€ãããã ããšãã°ãCã§åã宣èšããæ§æã¯ãçç±ããªãæ··ä¹±ããããŠãããå®è£ ããã®ã¯ãŸã£ããé¢çœããªãã§ãã
ããã«ãããããããé¿ããããªãããšãããã€ããããŸãã æåããæåŸãŸã§ãã¹ãŠã®æ©èœãå®çŸããããã«ãããããèããå€ããå¿ èŠããããŸãã ç®æšã«è¿ã¥ãã«ã€ããŠãé¢çœããšæããããšãã§ããŸãã æã«ã¯ãç®æšãéæããããã«å¿ èŠä»¥äžã®ã³ãŒããæžãå¿ èŠããããŸãã
25æ¥ç®
ç§ã¯2æ¥éãå®çŸ©ãšå®£èšã®æ§æãå®è£ ããããšã«æåããŸããããæåããŸããã§ããã ãªããããçµäºã§ããªãã®ã§ããïŒ ç§ã¯1æ¥ã®ä»äºã§ãã€ã³ã¿ãŒãšæ§é ãäœæããŸããã ç§ã¯ãããéå°è©äŸ¡ããŠããããã«æããŸãã ãã¶ãèšç»ãå¿ èŠã§ããïŒ
26æ¥ç®
ãã®ãããªå°é£ãªç¶æ³ã§ã¯ã1ãæã®é²æã確èªããããã«ãã³ã³ãã€ã©ããã£ã1ã€ã®ãã¡ã€ã«ã«å«ãŸããŠãããšããäºå®ãèŠããŠããå¿ èŠããããŸãã 圌ã¯åã«scanfïŒïŒã§æŽæ°ãèªã¿åããprintfïŒïŒã§æŽæ°ãå°å·ããŸããã å®éãç§ã¯1ãæã§éåžžã«æ·±å»ãªé²æ©ãéããŸããã ã¯ããã§ãããšæããŸãã
28æ¥ç®
宣èšãšå®çŸ©çšã®ããŒãµãŒã®äœæãçµäºããŸããã ç§ã倱æããçç±ã¯ãæåããããŸãã«ãå€ãã®è©³çŽ°ãæžã蟌ãããšããããã ãšæãã®ã§ããã¹ãŠãæ£ããç解ããŠããå®éã®ã³ãŒãã«å€æããããšã確èªããããã«æ¬äŒŒã³ãŒããæžããŸããã
ç§ã¯15幎è¿ãCãæžããŠããŸããããä»æ¥ã«ãªã£ãŠããããCã®åæ§æãç解ã§ãããšæããŸãããåäœããã³ãŒããæžããªãã£ãã®ã¯é©ãããšã§ã¯ãããŸããã ããã¯ãç§ããããæ£ããç解ããªãã£ãããã§ãã
æžããã°ããã®ã³ãŒãã¯è€éãããŠå£ããããã®ã§ãç§ãç解ããããšã¯ã§ããŸããã Cã®äœæè ã§ããããã¹ãªãããŒãã圌ããã£ãŠããããšã®çµæãç解ããŠãããšã¯æããªãã 圌ã¯æ§æãæãã€ããäºæ³ãããè€éãªã³ãŒããæžããæçµçã«ã¯ANSIå§å¡äŒã«ãã£ãŠæšæºåããããšæããŸãã ãã¹ãŠãæ£ããè¡ãå¿ èŠããããããæšæºåãããèšèªãå®è£ ããããšã¯å°é£ã§ãã ç¬èªã®ããã¡ãã®èšèªãæžãæ¹ãç°¡åã§ãã
29æ¥ç®
ããã«å€ãã®æŒç®åãå®è£ ããã³ãŒããã¯ãªãŒã³ã¢ããããŸããã
ä»æ¥ãåããŠãç§ã®ã³ã³ãã€ã©ãç§ã®ãã¡ã€ã«ã®1ã€ãã³ã³ãã€ã«ããããšãã§ããŸããã GCCã䜿çšããŠã³ã³ãã€ã«ãããä»ã®ãã¡ã€ã«ã«ãªã³ã¯ãããšãæ©èœããŠããããšãããããŸããã ãŸããçµæã®ã³ã³ãã€ã©ãåäœããããã§ãã ã¿ãŒã²ãããè¿ã¥ããŠããããã§ãã
30æ¥ç®
ä»æ¥ãç§ã¯ã¹ã€ããã±ãŒã¹ãå®è£ ããç¶è¡ããäžæããåŸè€ã«è¡ããŸããã gotoã®ãã¹ãã±ãŒã¹ãäœæãããšããã¹ãã³ãŒãã¯ããã«ã¯èªããªãã¹ãã²ããã£ã³ãŒãã«å€ãããŸããã ããã¯ç§ãç¬ãããã gotoããªãæ害ãšèããããã®ãã確èªããŸããã
31æ¥ç®
varargsã«å®è£ ãããé¢æ°ãã€ãŸãva_startãva_argãva_endã ãããã¯ããŸã䜿çšãããŸããããprintfãªã©ã®é¢æ°ãã³ã³ãã€ã«ããããã«å¿ èŠã§ããã
Cã®å¯å€åŒæ°ã®ä»æ§ã¯ãããèããããŠããŸããã ã¹ã¿ãã¯ãä»ããŠé¢æ°ã«ãã¹ãŠã®åŒæ°ãæž¡ããšãva_startãéåžžã«ç°¡åã«å®è£ ã§ããŸãããææ°ã®ããã»ããµãšææ°ã®åŒã³åºãèŠçŽã§ã¯ãé¢æ°ãåŒã³åºããªãŒããŒããããæžããããã«åŒæ°ãã¬ãžã¹ã¿ã«æž¡ãããŸãã ãããã£ãŠãä»æ§ã¯çŸå®ã«å¯Ÿå¿ããŠããŸããã
倧ãŸãã«èšãã°ãAMDã«ãã£ãŠæšæºåãããx86-64ã®ABIã§ã¯ãva_startã®æ¬¡ã®åŒã³åºãã«åããŠããã¹ãŠã®ã¬ãžã¹ã¿ãã¹ã¿ãã¯ã«ã³ããŒããããã«ãå¯å€æ°ã®åŒæ°ãæã€é¢æ°ãå¿ èŠã§ãã 圌ãã«ã¯ä»ã«éžæè¢ã¯ãªãã£ããšç解ããŠããŸãããããã§ããã¯ãåä»ã«èŠããŸãã
ä»ã®ã³ã³ãã€ã©ãå¯å€æ°ã®åŒæ°ãæã€é¢æ°ãã©ã®ããã«åŠçããã®ãçåã«æããŸããã TCCããããŒã調ã¹ãŸããããABI x86-64ãšäºææ§ããªãããã§ãã varargsã®ããŒã¿æ§é ãç°ãªãå Žåãva_listãæž¡ãé¢æ°ïŒvprintfãªã©ïŒã¯äºææ§ããªããªããŸãã ãŸãã¯ç§ã¯ééã£ãŠããŸããïŒ [ãããŠãç§ã¯æ¬åœã«ééã£ãŠããŸã-ãããã¯äºææ§ããããŸãã] ClangãèŠãŸããããçŽããããããã§ãã ç§ã¯ãããèªã¿ãŸããã§ããã ä»ã®ã³ã³ãã€ã©ãŒããå€ãã®ã³ãŒããèªã¿ããããšãèªåã®å®è£ ã®é¢çœããå°ç¡ãã«ããå¯èœæ§ããããŸãã
32æ¥ç®
å°ããªåé¡ãä¿®æ£ããæååãªãã©ã«ã®ãšã¹ã±ãŒãã·ãŒã±ã³ã¹ãè¿œå ããåŸïŒãŸã ã\ 0ããªã©ã¯ãããŸããã§ããïŒãå¥ã®ãã¡ã€ã«ãã³ã³ãã€ã«ããããšãå€æããŸããã ç§ã¯èªä¿¡ãæã£ãŠé²æ©ãæããŠããŸãã
6ã€ä»¥äžã®ãã©ã¡ãŒã¿ãŒãæã€é¢æ°ã®ãµããŒããå®è£ ããããšããŸãããã1æ¥ã§å®äºã§ããŸããã§ããã x86-64ã§ã¯ãæåã®6ã€ã®æŽæ°ãã©ã¡ãŒã¿ãŒã¯ã¬ãžã¹ã¿ãŒãä»ããŠæž¡ãããæ®ãã¯ã¹ã¿ãã¯ãä»ããŠæž¡ãããŸãã çŸåšãã¬ãžã¹ã¿ãä»ãã転éã®ã¿ããµããŒããããŠããŸãã ã¹ã¿ãã¯ãééãããããšã¯å®è£ ããã®ãé£ããããšã§ã¯ãããŸãããããããã°ããã«ã¯æéãããããããŸãã ç§ã®ã³ã³ãã€ã©ã«ã¯ã6ã€ä»¥äžã®ãã©ã¡ãŒã¿ãæã€é¢æ°ã¯ãªãã®ã§ãä»ã®ãšããå®è£ ã延æãããšæããŸãã
33æ¥ç®
ä»æ¥ãããã«3ã€ã®ãã¡ã€ã«ãã³ã³ãã€ã«ãããŸããã 11ã®ãã¡6ã€ã§ãããã ããã³ãŒãã®è¡ãæ°ãããšãåèšã®çŽ10ïŒ ã«ãªããŸãã æ®ãã®ãã¡ã€ã«ã¯ãã³ã³ãã€ã©ã³ã¢ã®ã³ãŒããå«ãŸããŠãããããã¯ããã«å€§ãããªããŸãã
ããã«æªãããšã«ãè€åãªãã©ã«ãæå®ãããåæååãªã©ãã«ãŒãã«ãã¡ã€ã«ã§æ¯èŒçæ°ããCæ©èœã䜿çšããŸãã ãããã¯èªå·±ã³ã³ãã€ã«ãéåžžã«è€éã«ããŸãã ç§ã¯ãããã䜿ãã¹ãã§ã¯ãããŸããã§ããããæ®éã®å€ãCã§ã³ãŒããæžãçŽãããšã¯çç£çã§ã¯ãªãã®ã§ãã³ã³ãã€ã©ã§ãããããµããŒãããããšæããŸãã æéãããããŸããã
34æ¥ç®
ãããã°ããŒã«ã«é¢ããããã€ãã®æ³šæã ã³ã³ãã€ã©ã¯å€ãã®ã¹ãããã§æ§æãããè€éãªã³ãŒãã§ããããããããã°ã®ããã«äœããã®æ¹æ³ã§ã³ã³ãã€ã©ã調ã¹ãæ¹æ³ãå¿ èŠã§ãã ç§ã®ã³ã³ãã€ã©ãäŸå€ã§ã¯ãããŸããã 䟿å©ã ãšæãããã€ãã®æ©èœãå®è£ ããŸããã
ãŸããåå¥è§£æããã°ã©ã ã¯èªã¿åãäœçœ®ãèšæ¶ããäºæããªãçç±ã§äžæãããå Žåããã®äœçœ®ãè¿ããŸãã ããã«ãããã³ã³ãã€ã©ãæ£ããå ¥åãåãå ¥ããªãå Žåã«ãã°ãç°¡åã«èŠã€ããããšãã§ããŸãã
å éšæœè±¡æ§æããªãŒãå°å·ããããã®ã³ãã³ãã©ã€ã³ãªãã·ã§ã³ããããŸãã ããŒãµãŒã«ãšã©ãŒãããå Žåãæ§æããªãŒã確èªããããšæããŸãã
ã³ãŒããžã§ãã¬ãŒã¿ãŒã¯ãæœè±¡æ§æããªãŒãèµ°æ»ãããšãã«ã¢ã»ã³ãã©ãŒã³ãŒãã®ãã©ã°ã¡ã³ããçæãããããååž°ãåºã䜿çšã§ããŸãã ãã®ãããã¢ã»ã³ãã©ãŒåºåã®åè¡ã«å¯ŸããŠããã¹ã¿ââãã¯ãã¬ãŒã¹ã®å°å·ãå®è£ ããããšãã§ããŸããã äœãããããããšã«æ°ã¥ãããããã®åºåãèŠãããšã§ã³ãŒãçæããã°ã©ã ããã©ãããšãã§ããŸãã
ã»ãšãã©ã®å éšããŒã¿æ§é ã«ã¯ãæååã«å€æããããã®é¢æ°ããããŸãã ããã¯ããããã°ã«printfã䜿çšãããšãã«äŸ¿å©ã§ãã
æ°ããé¢æ°ãäœæãããšãã¯ãåžžã«ãŠããããã¹ããäœæããŸãã å®è£ ãããšããŠãããã¹ããå®è¡ããããã«ã³ãŒããã³ã³ãã€ã«ãããŸãŸã«ããŸãã ãã¹ãã¯çæéã§å®è¡ãããããã«èšè¿°ãããŠãããããäœåºŠã§ãå®è¡ã§ããŸãã
36æ¥ç®
è€åãªãã©ã«ãå®è£ ããæ§é äœãšé åã®åæååãæžãçŽããŸããã 以åã®å®è£ ã¯æ°ã«å ¥ããªãã£ãã ããã§ãã€ãã·ã£ã©ã€ã¶ãæ¹åãããŸããã ç§ã¯æåããçŸããã³ãŒããæžããªããã°ãªããŸããã§ããããåäœããã³ãŒããæžãããšã§ããç解ã§ããªãã£ããããæžãæãã¯é¿ããããŸããã§ããã
èªå·±ã³ã³ãã€ã«ã«ã¯äžååãªå¯äžã®æ©èœã¯ãæ§é ã®å²ãåœãŠã ãšæããŸãã å®è£ æã«å€ãã®ãããã°ãªãã§ãã¹ãŠãæå³ãããšããã«æ©èœããããšãé¡ã£ãŠããŸãã
37æ¥ç®
ããŒã¯ãã€ã¶ãŒãå«ããã¡ã€ã«ã¯ã³ã³ãã€ã«ãããŸãããäœããã®çç±ã§çµæã®ç¬¬2äžä»£ã³ã³ãã€ã©ãŒãæ£ããã¢ã»ã³ãã©ãŒã³ãŒããçæããŸããã ãã ãã第äžäžä»£ã®ã³ã³ãã€ã©ãŒã«ãã£ãŠçæãããã³ãŒãã¯ãã¹ãŠã®ãã¹ãã«åæ ŒããŸãã ãã®ãããªé°æ¹¿ãªãã°ã
第2äžä»£ã¯ãããã°æ å ±ããµããŒãããŠããªãã³ã³ãã€ã©ãŒã§ã³ã³ãã€ã«ãããŠããããããããã°ã«printfã䜿çšãã以å€ã«éžæè¢ã¯ãªããšæããŸãã çãããå Žæã«printfãè¿œå ããŸããã 第2äžä»£ã®ã³ã³ãã€ã«æã«Printfãããã°ã¡ãã»ãŒãžã衚瀺ãããã®ã§ãå°ãé©ããŸããã 第2äžä»£ã䜿çšããå Žåã«ã®ã¿ãããã°ã¡ãã»ãŒãžãåºåãããã®ã§ã第2äžä»£ãäœæãããã°ããã®ãšãã«åºåãæ©èœãããšã¯æã£ãŠããŸããã§ãã ã
æ ç»ãBeginningããæãåºãããŸãã ãã®ãã°ãåçŸããã«ã¯ãããã«æ·±ãããå¿ èŠããããŸãã ããã¯ãèªå·±ã³ã³ãã€ã«ã³ã³ãã€ã©ã®ãããã°ã®æ¥œããéšåã§ãã
38æ¥ç®
åå¥è§£æããã°ã©ã ãèªå·±ã³ã³ãã€ã«ãããå Žåã«ã第2äžä»£ã§çºçããåé¡ãä¿®æ£ããŸããã -1> 0ãæã trueãè¿ããã°ãåŒãèµ·ãããŸããïŒç¬Šå·æ¡åŒµãå¿ããŠããŸããïŒã æ§é ã®é 眮ïŒæ§é ã¬ã€ã¢ãŠãïŒã«ã¯å¥ã®ãã°ããããŸãã æ®ã£ãŠãããã¡ã€ã«ã¯3ã€ã ãã§ãã
39æ¥ç®
ã³ãŒããžã§ãã¬ãŒã¿ãŒãã³ã³ãã€ã«ã§ããããã«ãªããŸããã æ®ã2ã€ã®ãã¡ã€ã«ã ç§ã¯æ¥œèŠ³çã§ã¯ãªããããããŸããããäœæ¥ã¯ã»ãŒå®äºããŠããŸãã äºæããªãèœãšãç©ŽããŸã æ®ã£ãŠããå¯èœæ§ããããŸãã
ãã®ãããžã§ã¯ãã®åæ段éã§æžããã³ãŒãã®è³ªã®äœãã«èµ·å ããå€ãã®åé¡ãä¿®æ£ããŸããã ããã¯ç§ãéå±ãããã
èªå·±ã³ã³ãã€ã«ã®æ©äŒã¯ãã¹ãŠãããšä¿¡ããŠããŸããããããã§ã¯ãããŸããã ãã¬ãã£ãã¯ã¹ã®ã€ã³ã¯ãªã¡ã³ã/ãã¯ãªã¡ã³ãæŒç®åããããŸããã C99ã®äžéšã®æ©èœã«ã€ããŠã¯ãã³ã³ãã€ã©ãŒéšåãæžãçŽããŠã³ã³ãã€ã«ããããããŸããã èªå·±ã³ã³ãã€ã«ã®å¯èœæ§ã«ããã»ã©æ©ãå°éããããšãæåŸ ããŠããªãã£ããããå¿ èŠãªã ãå€ãã®æ°ããCæ©èœã䜿çšããŸããã
40æ¥ç®
ãã£ãïŒç§ã®ã³ã³ãã€ã©ã¯å®å šã«ã³ã³ãã€ã«ã§ããããã«ãªããŸããïŒ
çŽ40æ¥ããããŸãããããã¯ãèªå·±ã³ã³ãã€ã«Cã³ã³ãã€ã©ãæžãããã®éåžžã«çãæéã§ããç§ã®ã¢ãããŒãã¯ãæåã«éåžžã«éãããCã®ãµãã»ããçšã®å°ããªã³ã³ãã€ã©ãäœæãããããå®éã®Cã³ã³ãã€ã©ã«å€æããŠéåžžã«ããŸãæ©èœãããããšã ãšæããŸãããããã«ãããä»æ¥ã¯ãšãŠã幞ãã§ãã
èªåã®ã³ãŒããèŠãŠãèªåã§äœæããããšãç¥ã£ãŠããŠããå ¥åã§èªåèªèº«ãåãå ¥ããŠã¢ã»ã³ãã©ãŒã«å€æã§ãããããå°ãéæ³ã®ããã«æããŸãã
ãŸã å€ãã®ãã°ãšæªå®çŸã®æ©èœããããŸããããããããããçµäºããŠãããåºåã³ãŒãã®æ¹åã«åãçµã¿ãŸãã
ãœãŒã¹ã³ãŒãã¯ãã¡ãã§ãããèªã䟡å€ããããã©ããã¯ããããŸããããåçŽãª5000è¡ã®ã³ã³ãã€ã©ãŒãåŠçã§ããCã³ãŒãã®ãµã³ãã«ãšããŠèŠãã®ã¯é¢çœããããããŸããã
41æ¥ç®
倧ããªãã€ã«ã¹ããŒã³ã«å°éããããã圌ã¯äœç³»çãªéçºã«æ»ããŸãããã³ãŒããå€æŽããŠããããã第äžè ã§ãããã®ããã«èªã¿èŸŒãããšããçµæãã³ãŒãã®å質ã«æºè¶³ããŸãããçæ œã®åªå®ãé£æ³ãããŸãã
ã»ã«ãã³ã³ãã€ã«ãåéãããã¹ããè¿œå ããŠã第2äžä»£ãšç¬¬3äžä»£ã®ãã¡ã€ã«ã§çµæãåãã§ããããšã確èªããŸãããç§ã®èšæ¶ãæ£ãããã°ãGCCã«ãåæ§ã®ãã¹ãããããŸãã
42æ¥ç®
ã³ã³ãã€ã©ã®ãœãŒã¹ã³ãŒãã«æžã蟌ãŸããŠããªãã«ããããããããã€ããªåœ¢åŒã®å®è¡å¯èœãã¡ã€ã«ãä»ããŠã®ã¿æ¬¡äžä»£ã«éä¿¡ã§ããæ å ±ãããã€ããããŸãã
ããšãã°ãç§ã®ã³ã³ãã€ã©ã¯ãã\ nãïŒããã¯ã¹ã©ãã·ã¥ãšæåãnãã®ã·ãŒã±ã³ã¹ïŒãæååãªãã©ã«ã\ nãïŒãã®å Žåã¯æ¹è¡æåïŒã«è§£éããŸããèããŠã¿ããšãã\ nãã®å®éã®ASCIIã³ãŒãã«é¢ããæ å ±ããªããããããã¯å°ããããããããããŸãããæåã³ãŒãã«é¢ããæ å ±ã¯ãœãŒã¹ã³ãŒãã«ã¯ãããŸããããã³ã³ãã€ã©ãã³ã³ãã€ã«ããã³ã³ãã€ã©ããéä¿¡ãããŸããç§ã®ã³ã³ãã€ã©ã®æ¹è¡ã¯ãGCCã«ãŸã§ããã®ãŒãããšãã§ããŸãã
ã³ã³ãã€ã©ã¯ãæåã³ãŒããããã¯ããã«å€ãã®æ å ±ãäŒããããšãã§ããŸãã
ãã®é©ãã¹ãç©èªã¯ãã±ã³ã»ãã³ããœã³ããã¥ãŒãªã³ã°è³ã®åè³ã«é¢ããè¬æŒã§çºè¡šãããã®ã§ããKenã以åã®ããŒãžã§ã³ã®Unixã³ã³ãã€ã©ã«è¿œå ããæ å ±ã«ããããŠãŒã¶ãŒãã°ã€ã³ããã°ã©ã ã¯ããã€ãã®ç¹å¥ãªãã¹ã¯ãŒããåãå ¥ããããšãã§ãããããKenã¯ä»»æã®Unixã¢ã«ãŠã³ãã«ãã°ã€ã³ã§ããŸããããŸããã³ã³ãã€ã©ãŒã«ç¬èªã®ã³ã³ãã€ã«ãèªèãããå ¥åããã°ã©ã ã®ããã¯ãåã³ã³ãã€ã©ãŒã«æž¡ãããšã§ããã®ããã¯ãã¢ïŒãœãŒã¹ã³ãŒãã«ãªãïŒãäžä»£ããäžä»£ãžãšæž¡ãããããã«ããŸããããœãŒã¹ã³ãŒããåŠçããã³ã³ãã€ã©ãææããŠãããããã³ã³ãã€ã©ã®ãœãŒã¹ã³ãŒãã®ãã¹ãŠã®è¡ãæ éã«èª¿ã¹ãŠåã³ã³ãã€ã«ããŠããåé€ã§ããŸããã§ãããããã¯çŽ æŽããã話ã§ããã
43æ¥ç®
æŒç®åã®åªäœæ§ïŒæŒç®ååªå é äœããŒãµãŒïŒã䜿çšãã代ããã«ãååž°éäžã®æ¹æ³ã§æŒç®åã®ããŒãµãŒã®å®è£ ãæžãçŽããŸãããæŒç®åã®åªå é äœã䜿çšããŠããŒãµãŒãéžæããçç±ã¯ãåçŽããšé床ã«ãããšæããŸãããæŒç®åã®Cã¹ããŒãã¡ã³ãã§äœ¿çšãããææ³ã¯ããã®æ¹æ³ã§åŠçããã«ã¯æ··ä¹±ããããŠããŸãïŒããšãã°ãé åã€ã³ããã¯ã¹ãŸãã¯ããŸããŸãªçš®é¡ã®åé æŒç®åïŒã倧ããªé¢æ°ã¯å€ãã®å°ããªé¢æ°ã«åå²ããããããã³ãŒãã¯ä»¥åãããèªã¿ããããªããŸãããããŒãµãŒã«ãšã©ãŒãã§ãã¯ãè¿œå ããã®ãç°¡åã«ãªããŸããã
ããŒãµãŒäœæãã¯ããã¯ã¯ãããã°ã©ããŒãšããŠã®ç§ã®æã圹ç«ã€ã¹ãã«ã®1ã€ã§ãã圌ã¯äœåºŠãå©ããŠãããŸããã
ããããååž°èšèªã䜿çšããŠææ³ã®ããŒãµãŒãèšè¿°ããããã«Cèšèªä»æ§ãèªãã ãšããããã€ãã®æŽŸçèªãååž°çã«æ®ãããŠããããšãããããŸãããç§ã¯ãã°ããèããŠãæç§æžãããäžåºŠéããŠãææ³ãæ£ããååž°ããããã«æžãçŽãæ¹æ³ãæãåºããªããã°ãªããŸããã§ãããå·Šååž°ã®æé€ã¯æ§æ解æã®åºæ¬çãªãããã¯ã§ãããããã¯å ¥éæžã§èª¬æãããŠããŸããããããç§ã¯é·ãéãã®æè¡ã䜿çšããŠããªãã£ãã®ã§ããã®ãããªåºæ¬çãªããšãæãåºãããšãã§ããŸããã§ããã
44æ¥ç®
å ¥åããŒã¿ã¯ãæååâããŒã¯ã³ã·ãŒã±ã³ã¹âãã¯ã眮æåŸã®ããŒã¯ã³ã·ãŒã±ã³ã¹âæœè±¡æ§æããªãŒâx86-64ã¢ã»ã³ãã©ãŒã®ããã«å€æãããŸãããããããããéãã§æ··ä¹±ããŠããæåŸã®ç§»è¡ãæé»çãªåå€æããã¢ã»ã³ããªã³ãŒãã®çæäžã®ã©ãã«åã®å±éãªã©ãããŸããŸãªçš®é¡ã®æäœãå®è¡ããŸããçè«çã«ã¯ãããããASDãšã¢ã»ã³ãã©ãŒã®éã®äžéèšèªãå®çŸ©ããå¿ èŠããããŸãã
ç§ã¯å®å šã«ãããç解ããŠãããšæããã«ããã®äž»é¡ã«ã€ããŠåã³ãã©ãŽã³ããã¯ãèªã¿ãŸããããã®æ¬ã¯ããŸãã«ãæœè±¡çãªã®ã§ãããã«ç§ã®ã±ãŒã¹ã«é©çšããããšã¯ã§ããŸããã
ç§ã®ã³ã³ãã€ã©ã¯ãã³ã³ãã€ã«æã«GCCã®2åé ããªããŸããããã¯æã£ãã»ã©æªãã¯ãããŸãããç§ã®ã³ã³ãã€ã©ã¯ã²ã©ãèžè¡çãªã¢ã»ã³ãã©ãŒãçæããŸããããã®ãããªã³ãŒãã¯äžæ¡ãé ããããŸããã
45æ¥ç®
gcovãç§ã®ã³ãŒãã§ã©ã®ããã«æ©èœããã®ããšæã£ãŠããŸããã圌ã¯ãåäœãã¹ãã«å€±æããã³ãŒãã®å€ãã®ãã©ã³ããèŠã€ããŸããããããã®ã³ãŒããã©ã³ãã®ãã¹ããè¿œå ããããšã§ãããã€ãã®ãã°ãçºèŠããŸãããã³ãŒãã«ãã¬ããžããŒã«ã¯éåžžã«äŸ¿å©ã§ãã
46æ¥ç®
ã³ã³ãã€ã©ãŒãã©ããããã«ã€ããŠã®ã¢ã€ãã¢ãäžè¶³ããŠããããã«æããŸããæ°ããããšãåŠã¶å¿ èŠã¯ãªãã£ãã®ã§ãéçºã®çŸç¶ã«å°éããããšã¯é£ãããããŸããã§ãããããã®ç¹ä»¥å€ã®ããšã¯é£ããããã§ãã
ã³ãŒããžã§ãã¬ãŒã¿ãŒããæé»çãªåå€æãåŒãåºããŸããããããã¯çŸåšãASDã§æ確ã«è¡šãããŠããŸããããã«ãããå éšã§äœãèµ·ãã£ãŠããã®ããç°¡åã«ç解ã§ããŸãããŸããããŸããŸãªå Žæã§å¶ç¶ã®æ¹åãè¡ããŸãããäœæ¥ã¯ã»ãŒå®äºãããšæããŸããããå®éã«ã¯å€ãã®æªå®çŸã®æ©èœãšãšã©ãŒããããŸããã
Dragon Bookããããã«ããã€ãã®ããŒãžãèªãã åŸãã³ã³ãã€ã©ãŒã®æé©åãããããç解ãå§ããŸãããããå°ãè¯ãç解ã§ããã°ãã³ãŒããæžãå§ããããšãã§ããŸãã
52æ¥ç®
è¬ã®ãã°ã3æ¥éæ¢ããŸãããã¹ã¿ãã¯ãã€ã³ã¿ãŒãåãäžããŠ16ãã€ãã®å¢çã«åããããšã第2äžä»£ã®ã³ã³ãã€ã©ãŒã¯æ£ããå ¥åã«å¯ŸããŠãšã©ãŒã¡ãã»ãŒãžã衚瀺ããŸãããããã®çš®é¡ã®ãšã©ãŒã¯ãéåžžã®èŽåœçãªãšã©ãŒããããããã°ãå°é£ã§ãã
ç§ã®æåã®æšæž¬ã¯ïŒã¹ã¿ãã¯ã¹ã¿ãã¯ãã€ã³ã¿ãŒã®äžæŽåã§ããããããããã¯ããã§ã¯ãããŸãããã¹ã¿ãã¯ãã€ã³ã¿ãŒã16ãã€ãå¢çã«æ¢ã«æ£ããé 眮ãããŠããããã§ããã¢ã»ã³ãã©ãŒã®åºåã«ãã°ãèŠã€ãããŸããã§ãããç§ã¯ååã«åå²ããããšã«ããŸããã
ã³ã³ãã€ã©ãŒã§åãã¡ã€ã«ãã³ã³ãã€ã«ããæ®ããGCCã§ã³ã³ãã€ã«ããŠãåé¡ãåçŸã§ããé¢æ°ã決å®ããããšããŸãããããããé¢æ°ã«ã¯ãšã©ãŒãå«ãŸããŠããªãã£ãããã§ããããã¯ããšã©ãŒã¡ãã»ãŒãžã衚瀺ããé¢æ°ã§ã¯ãããŸããã1ã€ã®ãã¡ã€ã«ã«ãããããŸãããçè«ã¯ã1ã€ã®é¢æ°ãä»ã®é¢æ°ã§ãšã©ãŒãåŒãèµ·ããäžæ£ãªããŒã¿ãäœæãããšãããã®ã§ãã
é·æéã®å¶ç¶ã®ãããã°ã®åŸãç§ã¯æçµçã«çç±ãèŠã€ããŸããïŒã³ã³ãã€ã©ã¯ãŒãã§æ§é äœãã£ãŒã«ããåæåããŸãããCä»æ§ã§ã¯ãæ§é äœãå€ã§åæåãããŠããªããã£ãŒã«ããåæåãããšããã³ã³ãã€ã©ã¯èªåçã«ãŒãã§åããå¿ èŠããããŸããç§ã¯ã³ãŒããæžãããšãã«ä»æ§ãç¥ã£ãŠããŸããïŒãããã£ãŠãç§ã®ã³ãŒãã¯ãã®åäœã«äŸåããŸãïŒãããããå®è£ ããã®ãå¿ããŠããŸããããã®çµæãäžéšã®æ§é äœãã£ãŒã«ãã¯ãŒãã§ã¯ãªããŽãã§åæåãããŸãããã¬ããŒãžããŒã¿ã¯ã¹ã¿ãã¯ã®çŸåšã®äœçœ®ã«å¿ããŠå€åãããããã¹ã¿ãã¯ãã€ã³ã¿ãŒãå€æŽãããšããã°ã©ã ã®åäœãã©ã³ãã ã«å€åããŸãã
ãã®çµæã3æ¥éã®ãããã°åŸã1è¡ã®ã¿ãä¿®æ£ãããŸããããã®ãããªãããã°ãç°¡çŽ åããæ段ã欲ããã®ã§ãã
53æ¥ç®
å¥ã®è¬ã®ãã°ãä¿®æ£ãããŸãããäžéšã®ãã¡ã€ã«ãGCCã§ã³ã³ãã€ã«ããæ®ããç§ã®ã³ã³ãã€ã©ã§ã³ã³ãã€ã«ãããšãçµæã®ã³ã³ãã€ã©ã¯æå¹ãªå ¥åã§æ§æãšã©ãŒãå ±åããŸãããã®ãããªåé¡ã¯ãABIã®äºææ§ã«é¢é£ããå¿ èŠããããŸããç§ã®æåã®ä»®å®ã¯ãåé¡ã¯æ§é ã®ããŒã¯ã¢ãããŸãã¯åŒæ°ãé¢æ°ã«æž¡ãããæ¹æ³ã«ãããããããªãããã¢ã»ã³ãã©ãŒã®åºåã¯ãããã«å¯ŸããŠæ£ããããã ãšããããšã§ããã
ããäžåºŠãæ€çŽ¢ãç¹å®ã®ãã¡ã€ã«ã«çµã蟌ã¿ãååã«å ±æããŸãããåé¡ãåŒãèµ·ãããŠããé¢æ°ãèŠã€ããããã«ããããã¡ã€ã«ããå¥ã®ãã¡ã€ã«ã«é¢æ°ãé çªã«è»¢éããŸããããã®é¢æ°ã¯å°ãããªãã£ãã®ã§ãç§ã¯ãããåé¢ããã³ãŒããå¥ã®ãã¡ã€ã«ã«è»¢éããŸãããæåŸã«ãã³ãŒããæ°è¡ååŸããŸããã GCCãšã³ã³ãã€ã©ã䜿çšããŠããããã³ã³ãã€ã«ããæ¯èŒããŸããã
å¯äžã®éãã¯ããã§ããã³ã³ãã€ã©ã¯ã¬ãžã¹ã¿ã®ãã¹ãŠã®ãããããã§ãã¯ããŠãããŒã«å€trueãå«ãŸããŠãããã©ãããå€æããŸãããGCCã¯äžäœ8ãããã®ã¿ããã§ãã¯ããŸãããããã£ãŠãäŸãã°ãã¬ãžââã¹ã¿ãŒã®å€ã512ïŒ= 2 9ãŸãã¯0x100ïŒã®å Žåãã³ã³ãã€ã©ãŒã¯ãããtrueãšèŠãªããŸãããGCCã¯å¥ã®æ¹æ³ã§ãããèæ ®ããŸãã GCCã¯å®éã«ã¯ãæäžäœ8ãããã«ãŒããå«ãéåžžã«å€§ããªæ°ãè¿ããŸãããããã¯falseãšè§£éãããŸãã
ãã®éäºææ§ã®ãããGCCã䜿çšããŠã³ã³ãã€ã«ãããé¢æ°ã䜿çšããŠçµäºæ¡ä»¶ããã§ãã¯ããã«ãŒãïŒã«ãŒãèªäœã¯ã³ã³ãã€ã©ãŒã«ãã£ãŠã³ã³ãã€ã«ãããŸãïŒã¯ãæåã®å埩ã§ããã«åæ¢ããŸãããã®çµæãããªããã»ããµãã¯ãã¯å®çŸ©ãããŠããŸããããŸããäžéšã®ããŒã¯ã³ã¯æªå®çŸ©ã®ãŸãŸã§ãã£ããããããŒãµãŒã¯äžéšã®å ¥åããŒã¿ã§æ§æãšã©ãŒãå ±åããŸããããã®çç±ã¯ããšã©ãŒãå ±åãããå Žæããã¯ã»ã©é ããã®ã§ããããæçµçã«ã¯ãããèŠã€ããŸããã
x86-64 ABIä»æ§ã«ã¯ãäžäœ8ãããã®ã¿ãè«çæ»ãå€ã«ãšã£ãŠéèŠã§ãããšããç°¡åãªã¡ã¢ããããŸããç§ã¯ãããèªã¿ãŸããããåããŠãããäœãæå³ããã®ãç解ã§ããªãã£ãã®ã§ããã®ãããªå åãååšããããšããèŠããŠããŸããã§ããããããä»ãç§ã«ãšã£ãŠã¯éåžžã«æ確ã§ããç§ã¯è€éãªææ ãæã£ãŠããŸã-æ°ããããšãåŠã³ãŸããããããã»ã©æéãè²»ããããšãªãããããåŠã¶ããšãã§ããŸããã
55æ¥ç®
ããããã£ãŒã«ããå®è£ ããŸããã
ããããã£ãŒã«ãã䜿çšããŠãããã€ãã®å€æ°ãå°ããªé åã«ããã¯ã§ããŸãããã³ã³ãã€ã©ãŒã¯ããããã®ã¿ã€ãã«å¿ããŠããããã®éã«ã¹ããŒã¹ãäœæããå¿ èŠããããŸããGCCã®çµè«ã«é¢ããç°¡åãªèª¿æ»ã«ããã次ã®ã«ãŒã«ãæããã«ãªããŸããïŒãã¡ãããããããæ£ããããšãä¿èšŒãããã®ã§ã¯ãããŸããïŒã
- . , «int x:5», x 4- (, int â 32 ).
- . , «int x:10», x 4- . , , .
CPUã«ã¯ã¡ã¢ãªå ã®åã ã®ãããã«ã¢ã¯ã»ã¹ããããã®åœä»€ããªããããããããã£ãŒã«ãã«ã¢ã¯ã»ã¹ããã«ã¯è€æ°ã®æ©æ¢°åœä»€ãå¿ èŠã§ããããããã£ãŒã«ããå«ãã¡ã¢ãªãã¬ãžã¹ã¿ã«èªã¿èŸŒãå¿ èŠããããŸãã次ã«ãïŒãã¹ã¯ã䜿çšããŠããããã£ãŒã«ããèªã¿åããŸããã¡ã¢ãªã«æžã蟌ããšãã¯ãæåã«ããããã£ãŒã«ããå«ãã¡ã¢ãªãèªã¿åããããããã¹ã¯ïŒããããåäœã®ããŸãã¯ããé©çšããŠæ°ããå€ãååŸãã次ã«å€ãã¡ã¢ãªã«æžãæ»ãå¿ èŠããããŸãã
56æ¥ç®
èšç®ãããgotoïŒèšç®ãããgotoïŒãå®è£ ããŸãããéåžžã®gotoã¯1ã€ã®ã©ãã«ããåç §ã§ããŸããããèšç®ãããgotoã¯ãã€ã³ã¿ãŒãåãããã®ã¢ãã¬ã¹ã«å¶åŸ¡ãæž¡ãããšãã§ããŸããããã¯Cæšæºã«ã¯ãªããGCCã®æ¡åŒµæ©èœãšããŠååšããŸããéåžžã«å€§ããªã¹ã€ããã±ãŒã¹ã䜿çšããŠä»®æ³ãã·ã³ãäœæããããšãããå Žåã¯ããã®æ©èœããåç¥ã§ãããããã®é¢æ°ã¯ã倧èŠæš¡ãªã¹ã€ããã±ãŒã¹ã¹ã€ãããå€æããŒãã«ãšèšç®ãããgotoã§çœ®ãæããããã«ãã䜿çšãããŸãã
èšç®ãããgotoã¯ãåäžã®éæ¥ãžã£ã³ãåœä»€ã«ã³ã³ãã€ã«ãããŸããããã¯ãããããã¢ã»ã³ãã©ãŒã®èŠ³ç¹ããç解ããããã§ããããç§ã®ã³ã³ãã€ã©ã¯ã¢ã»ã³ãã©ãçæãããããå®è£ ã¯éåžžã«ç°¡åã§ããã
57æ¥ç®
ã³ã³ãã€ã©ã§äœ¿çšãããã£ããããC11 _Genericãå®è£ ããŸãããããããå®è£ åŸãGCC 4.6.1ã¯_GenericããµããŒãããŠããªãããšã«æ°ä»ããŸããããã®é¢æ°ã䜿çšãããšãGCCãã³ã³ãã€ã©ãã³ã³ãã€ã«ã§ããªãããã䜿çšã§ããŸããã
ãŸããGCCã®æ¡åŒµæ©èœã§ããtypeofïŒïŒé¢æ°ãå®è£ ããŸããããããã®é¢æ°ã¯äž¡æ¹ãšãçŸæç¹ã§ã¯äœ¿çšãããŠããŸããããããããå®è£ ããã®ã«å¿ èŠãªã³ãŒãã¯ã»ãšãã©ãªããããããã¯æ£åžžã§ãã
58æ¥ç®
C99ããæåã°ã©ããè¿œå ããŸããããã€ã°ã©ãã¯ãäžéšã®æåã䜿çšã§ããªãç¹å®ã®ç°å¢ã§ã¯çããæ©èœã§ããããšãã°ãã<ïŒãã¯ã[ãã®ãšã€ãªã¢ã¹ãšããŠå®çŸ©ãããŸãããã€ã°ã©ãã¯ãããŒã¯ã³åäžã«éåžžã®æåã«å€æã§ãããããç¡çšã§ããç¡å®³ã§ãã
C89ã«ã¯æããã«æ害ãª3æåããããŸãããã©ã€ã°ã©ãã¯ã3æåã®æåã·ãŒã±ã³ã¹ã§ããããœãŒã¹ã³ãŒãã®ã©ãã«ããå Žåã§ã1æåã«å€æãããŸããããšãã°ãprintfïŒ "huh ??ïŒ"ïŒã¯ãhuh ??ïŒãã§ã¯ãªãããhuh |ããšåºåããŸãããããã¯ã??ïŒãã ããã§ããããã¯ã|ãã®3æåè¡šèšã§ããããã¯éåžžã«çŽããããã§ããããªã°ã©ãããµããŒãããäºå®ã¯ãããŸããã
62æ¥ç®
TCCãã³ã³ãã€ã«ããããšããŠããŸãããããããããŸã§ã®ãšãããæªå®çŸã®æ©èœãšãšã©ãŒã®ããã«ç§ã¯æåã«ã¯ã»ã©é ãã
TCCã¯ããµã€ãºã20Kã30Kè¡ã®ã³ãŒãã®ç¯å²ã«ããå°ããªCã³ã³ãã€ã©ã§ãã x86-64以å€ã®ã¢ãŒããã¯ãã£ã®ãµããŒããåé€ããå Žåãè¡æ°ã¯çŽ10Kã20Kã«ãªãå¯èœæ§ããããŸãããã®ãããªå°ããªã³ã³ãã€ã©ãŒãéåžžã«å€ãã®æ©èœããµããŒãããŠããã®ã¯é©ãã§ããTCCã®äœæè ã§ããFabrice Bellarã¯å€©æã§ãã
TCCã®ãœãŒã¹ã³ãŒããæ°åèªãã§ã¿ãŸããããå šäœåãç解ã§ããŸãããã³ã³ãã€ã©ã¯è€éãªããã°ã©ã ã§ãããããéåžžã¯ç®¡çããããå°ããªéšåã«åå²ããå¿ èŠããããŸãããTCCãœãŒã¹ã³ãŒãã¯ã¢ããªã·ãã¯ã³ã³ãã€ã©ã®ããã«æããããŸãããããªã«ãã°ãããã³ãŒããæžãããšã¯ã§ããŸãããæš¡å£ããããã©ããã¯ããããŸãããããã®ãããªã³ãŒããæžãããšãã§ãã人ãäžçäžã«ãããšããäºå®ã¯æ¬åœã«æéãåããŸããã
73æ¥ç®
TCCã®ã³ã³ãã€ã«ã«å€±æããŸããããã¡ããããããé£ããã®ã¯ãåæ Œããã°ãã³ã³ãã€ã©ãŒãTCCãšåãæ©èœãæã€ããšãæå³ããããã§ããä»ã®ã³ã³ãã€ã©ã®ã³ã³ãã€ã«ã¯ãããã°ã«åœ¹ç«ã¡ãŸããããã®æ§è³ªäžãèšèªä»æ§ã®ãã¹ãŠã®è©³çŽ°ã现ããéžæããŠããŸãã