翻蚳è ããã®æ³šæïŒãã·ã¢èªã§ã¯ããã©ããã/ãã©ããã³ã°ããšããèšèã®äœ¿çšãããæèã«ã¯æ確ãªå¯Ÿå¿ããããŸããã 説æãããŠããçŸè±¡ã«è¿ãæ°åŠçšèªã 転é ãããããçšèªããã£ãªãŒãã©ã°ãã¯æŽæ°ãªãŒããŒãããŒäžã«ããã»ããµã«ãã©ã°ãèšå®ããã¡ã«ããºã ã§ãã å¥ã®ç¿»èš³ãªãã·ã§ã³ã¯ããå転/å転/ãŒããäžå¿ãšããå転ããšãããã¬ãŒãºã§ãã ããã£ãªãŒãããããã©ãããã®æå³ãããåæ ãããŠããŸãã æ£ã®ç¯å²ããè² ã®ç¯å²ã«ãªãŒããŒãããŒãããšãã®æ°å€ã®æšç§»ã瀺ããŸãã ããããå€æããããã«ããããã®åèªã¯ãã¹ããªãŒããŒã®ããã¹ãã§ã¯çããèŠããŸãã ç°¡åã«ããããã«ãå°æ¥çã«ã¯ã転éããšããèšèããã©ããããšããçšèªã®ç¿»èš³ãšããŠäœ¿çšããŸãã
äœæ¥äžã®CèšèªïŒããã³C ++ïŒã®ã³ã³ãã€ã©ãŒã¯ã äžå®ã®åäœã®æŠå¿µã«ãã£ãŠãŸããŸãå°ãããŠããŸã -äžéšã®æäœã®ããã°ã©ã ã®åäœã¯æšæºã«ãã£ãŠèŠå¶ãããŠãããããªããžã§ã¯ãã³ãŒããçæãããšããã³ã³ãã€ã©ãŒã¯ããã°ã©ã ããã®ãããªæäœãå®è¡ããªããšããä»®å®ããé²ãæš©å©ãæã£ãŠãããšããæŠå¿µ ãã®å Žåãçæãããã³ãŒãã¯ããã°ã©ã ã®äœæè ãæå³ãããšããã«åäœããªãå¯èœæ§ããããããå€ãã®ããã°ã©ãããã®ã¢ãããŒãã«å察ããŸããã ã³ã³ãã€ã©ãŒãããæŽç·Žãããæé©åææ³ã䜿çšããŠããããããã®åé¡ã¯ããæ·±å»ã«ãªã£ãŠããŸããããã¯ããããäžå®ã®åäœã®æŠå¿µã«åºã¥ããŠããã§ãããã
ããã«é¢é£ããŠã笊å·ä»ãæŽæ°ãªãŒããŒãããŒã®äŸã瀺ãããŠããŸãã ã»ãšãã©ã®Céçºè ã¯ã è¿œå ã®ã³ãŒãã䜿çšããŠæŽæ°ãè¡šããã·ã³çšã®ã³ãŒããèšè¿°ããŸãããã®è¡šçŸã§ã®å ç®ãšæžç®ã¯ããŸã£ããåãæ¹æ³ã§ç¬Šå·ãªãç®è¡ã§å®è£ ãããŸãã 笊å·ä»ãã®2ã€ã®æ£ã®æŽæ°ã®åèšããªãŒããŒãããŒããå Žåãã€ãŸããåã察å¿ãããµã€ãºãã倧ãããªã£ãå Žåãããã»ããµã¯ç¬Šå·ä»ãæ°å€ã®2é²è£æ°ãšããŠè§£éãããå€ãè² ãšèŠãªããŸãã ãã®çŸè±¡ã¯ã転éããšåŒã°ããŸããããã¯ãå€ã®ç¯å²ã®äžéã«éããçµæãã転éããããäžéããå§ãŸãããã§ãã
ãã®ãããCã§æ¬¡ã®ã³ãŒããèŠãããšãã§ããŸãã
int b = a + 1000; if (b < a) { // puts("input too large!"); return; }
ifã¹ããŒãã¡ã³ãã®ã¿ã¹ã¯ã¯ããªãŒããŒãããŒæ¡ä»¶ïŒãã®å Žåãå€æ°aã®å€ã«1000ãè¿œå ããåŸã«çºçãã ïŒãæ€åºãããšã©ãŒãå ±åããããšã§ãã åé¡ã¯ãCã§ã¯ã笊å·ä»ãæŽæ°ãªãŒããŒãããŒãæªå®çŸ©ã®åäœã®ã±ãŒã¹ã®1ã€ã§ããããšã§ãã ãã°ããã®éãã³ã³ãã€ã©ãŒã¯åžžã«ãã®ãããªæ¡ä»¶ãfalseãšèŠãªããŠããŸããã1000ïŒãŸãã¯ä»ã®æ£ã®æ°ïŒãå¥ã®æ°ã«å ç®ãããšãçµæã¯åæå€ããå°ãããªããŸããã ãªãŒããŒãããŒãçºçãããšãäžæ確ãªåäœãçºçããŸãããããèš±å¯ããªãããšã¯ããã§ã«ïŒæããã«ïŒããã°ã©ããŒèªèº«ã®é¢å¿äºã§ãã ãããã£ãŠãã³ã³ãã€ã©ãŒã¯ãæé©åã®ç®çã§æ¡ä»¶æŒç®åãå®å šã«åé€ã§ãããšå€æã§ããŸãïŒçµå±ãæ¡ä»¶ã¯åžžã«falseã§ãããäœã«ã圱é¿ããªãããããããªãã§ãå®è¡ã§ããŸãïŒã
åé¡ã¯ããã®æé©åã«ãããã³ã³ãã€ã©ãŒãæªå®çŸ©ã®åäœãæ€åºããŠåŠçããããã«ããã°ã©ããŒãè¿œå ãããã§ãã¯ãåé€ããããšã§ãã ããã§ã¯ãå®éã«ãããã©ã®ããã«èµ·ããããèŠãããšãã§ããŸãã ïŒæ³šïŒãµã³ãã«ããã¹ãããŠããgodbolt.orgãµã€ãã¯éåžžã«ã¯ãŒã«ã§ãïŒã³ãŒããç·šéããŠãããŸããŸãªã³ã³ãã€ã©ãŒãã©ã®ããã«åŠçããããããã«ç¢ºèªã§ããŸãã Cã§ç¬Šå·ãªããªãŒããŒãããŒã®åäœãå®çŸ©ãããŠãããããåã笊å·ãªãã«å€æŽããŠããã³ã³ãã€ã©ãŒã¯ãªãŒããŒãããŒã®ãã§ãã¯ãåé€ããªãããšã«æ³šæããŠãã ããïŒããæ£ç¢ºã«ã¯ãçµæã¯ç¬Šå·ãªãç®è¡ã§è»¢éãããããããªãŒããŒãããŒã¯å®éã«ã¯çºçããŸããïŒã
ããã¯ééã£ãŠããŸããïŒ å€ãã®ã³ã³ãã€ã©éçºè ããã®æ±ºå®ãåæ³ãšèŠãªããŠããããšã¯æããã§ããã誰ããã€ãšã¹ãšèšããŸãã ç§ãæ£ããç解ããŠããå ŽåããªãŒããŒãããŒæã®è»¢éã®ãµããŒã¿ãŒïŒç·šéïŒå®è£ äŸåïŒã®äž»ãªåŒæ°ã¯æ¬¡ã®ãšããã§ãã
- ãªãŒããŒãããŒã¯äŸ¿å©ãªåäœã§ãã
- 移è¡ã¯ãããã°ã©ããæåŸ ããåäœã§ãã
- ç¡æéã®ãªãŒããŒãããŒåäœã®ã»ãã³ãã£ã¯ã¹ã¯ãé¡èãªå©ç¹ãæäŸããŸããã
- æªå®çŸ©ã®åäœã«é¢ããCèšèªæšæºã«ãããå®è£ ã¯ãç¶æ³ãå®å šã«ç¡èŠããçµæã¯äºæž¬äžèœã«ãªããŸããããããã¯æªå®çŸ©ã®åäœã䌎ãç¶æ³ããŸã£ããçºçããªããšããä»®å®ã«åºã¥ããŠãã³ã³ãã€ã©ãŒã«ã³ãŒããæé©åããæš©å©ãäžããŸããã
åã¢ã€ãã ãé çªã«åæããŸãããã
ãªãŒããŒãããŒç§»è¡-æçšãªåäœïŒ
移è¡ã¯ãäž»ã«ããã§ã«çºçãããªãŒããŒãããŒã远跡ããå¿ èŠãããå Žåã«åœ¹ç«ã¡ãŸãã ïŒè»¢éã«ãã£ãŠè§£æ±ºã§ãã笊å·ãªãæŽæ°å€æ°ã䜿çšããŠè§£æ±ºã§ããªãä»ã®åé¡ãããå Žåããã®ãããªäŸãããã«æãåºããããããã®å€ãã¯ãªããšæãããŸãïŒã 転éã¯ã誀ã£ãŠãªãŒããŒãããŒããå€æ°ã䜿çšããåé¡ãå®éã«ç°¡çŽ åããŸãããäžèœè¬ã§ã¯ãããŸããïŒæªç¥ã®ç¬Šå·ãæã€2ã€ã®æªç¥ã®éã®ä¹ç®ãŸãã¯å ç®ãå¿ããªãã§ãã ããïŒã
äºçŽ°ãªã±ãŒã¹ã§ã¯ã転éã«ãã£ãŠãçºçãããªãŒããŒãããŒã远跡ã§ããå Žåããããçºçãããã©ãããäºåã«ç¥ãããšãé£ãããããŸããã ãã®äŸã¯æ¬¡ã®ããã«æžãæããããšãã§ããŸãã
if (a > INT_MAX - 1000) { // puts("input too large!"); return; } int b = a + 1000;
ã€ãŸããåèšãèšç®ããŠãããªãŒããŒãããŒãçºçãããã©ããã確èªããæ°åŠçãªäžè²«æ§ã®çµæã確èªãã代ããã«ãåèšãåã«é©åããæ倧æ°ãè¶ ããŠãããã©ããã確èªã§ããŸãã ïŒäž¡æ¹ã®ãªãã©ã³ãã®ç¬Šå·ãäžæãªå Žåãæ€èšŒã¯éåžžã«è€éã«ãªãå¿ èŠããããŸããã転éäžã®æ€èšŒã«ãåãããšãåœãŠã¯ãŸããŸãïŒã
ãã®ãã¹ãŠãèãããšãã»ãšãã©ã®å Žåã転移ãæçšã§ãããšãã説åŸåã®ãªãè°è«ãèŠã€ããŸãã
ããã°ã©ããŒãæåŸ ããåäœã¯ç§»è¡ã§ããïŒ
å°ãªããšãäžéšã® Cããã°ã©ããŒã®ã³ãŒãã笊å·ä»ãæŽæ°ãªãŒããŒãããŒã䌎ã転éã»ãã³ãã£ã¯ã¹ãæ³å®ããŠããããšã¯æããã§ããããããã®åŒæ°ã«ã€ããŠè°è«ããããšã¯ããå°é£ã§ãã ãããããã®äºå®ã ãã§ã¯ããã®ãããªã»ãã³ãã£ã¯ã¹ãæãŸãããšèããã«ã¯äžååã§ãïŒå¿ èŠã«å¿ããŠãäžéšã®ã³ã³ãã€ã©ãŒã§æå¹ã«ã§ããããšã«æ³šæããŠãã ããïŒã
åé¡ã«å¯Ÿããæãããªè§£æ±ºçïŒããã°ã©ããŒã¯ãã®åäœãæåŸ ããŸãïŒã¯ãæªå®çŸ©ã®åäœããªããšä»®å®ããŠãã³ãŒããæé©åãããšãã«ã³ã³ãã€ã©ãŒã«èŠåãåºãããšã§ãã æ®å¿µãªãããäžèšã®ãªã³ã¯ã䜿çšããgodbolt.orgã®äŸã§èŠãããã«ãã³ã³ãã€ã©ã¯åžžã«ãããè¡ããšã¯éããŸããïŒGccããŒãžã§ã³7.3-ã¯ããããŒãžã§ã³8.1-ããããããã§äžæ©åŸéããŸãïŒã
ç¡æéã®ãªãŒããŒãããŒåäœã®ã»ãã³ãã£ã¯ã¹ã«ã¯é¡èãªå©ç¹ã¯ãããŸãããïŒ
ãã®ã³ã¡ã³ãããã¹ãŠã®å Žåã«åœãŠã¯ãŸãå Žåãã³ã³ãã€ã©ã¯ããã©ã«ãã§è»¢éã»ãã³ãã£ã¯ã¹ã«åŸãã¹ãã§ãããšããäºå®ãæ¯æãã匷åãªåŒæ°ãšããŠæ©èœããŸããããã¯ããã®ã¡ã«ããºã ãæè¡çãªèŠ³ç¹ããééã£ãŠããŠãããããããªãŒããŒãããŒãã§ãã¯ãèš±å¯ããæ¹ãããããã§ãç Žæããå¯èœæ§ã®ããã³ãŒãã§äœ¿çšã§ããããã§ãã
éåžžã®Cããã°ã©ã ã§ã®ãã®æé©åïŒæ°åŠçã«ççŸããæ¡ä»¶ã®ãã§ãã¯ã®é€å»ïŒã¯ãäœè ãæé«ã®ããã©ãŒãã³ã¹ãç®æããŠåªåããã³ãŒããæåã§æé©åãããããç¡èŠãããããšãå€ããšæ³å®ããŠããŸãïŒã€ãŸãããã®ifã¹ããŒãã¡ã³ãã«æ¡ä»¶ãå«ãŸããŠããããšãæãããªå Žå ãããã¯æ±ºããŠçå®ã§ã¯ãããŸããããããã°ã©ããŒã¯èªåã§åé€ããå¯èœæ§ããããŸãã å®éãããã€ãã®ç 究ã§ããã®ãããªæé©åã®æå¹æ§ãçåèŠããããã¹ããããå¶åŸ¡ãã¹ãã®ãã¬ãŒã ã¯ãŒã¯ã§ã¯å®è³ªçã«éèŠã§ãªãããšãããããŸããã ãã ãããã®æé©åã¯Cã§ã¯ã»ãšãã©å©ç¹ãæäŸããŸããããã³ãŒããžã§ãã¬ãŒã¿ãŒãšã³ã³ãã€ã©ãŒã®æé©åã¯ã»ãšãã©ã®éšåã§æ®éçã§ãããä»ã®èšèªã§ã䜿çšã§ããŸãã C ++èšèªã䜿çšããŠã¿ãŸããããããšãã°ãæåã§è¡ãã®ã§ã¯ãªãããªããã£ãã€ã¶ãŒã«äŸåããŠãã³ãã¬ãŒãã³ãŒãå ã®åé·ãªæ§é ãåé€ãããšããäŒçµ±ããããŸãã ãããããã©ã³ã¹ããŒã¿ãŒã«ãã£ãŠCã«å€æãããèšèªãããããããã®åé·ã³ãŒããCã³ã³ãã€ã©ãŒã«ãã£ãŠæé©åãããŸãã
ããã«ããªãŒããŒãããŒããã§ãã¯ãç¶ããŠããè¿œå ã®ã³ãŒãã䜿çšãããã·ã³ã§ãã£ãŠããæŽæ°å€æ°ã転éããçŽæ¥çãªã³ã¹ããæå°éã«ãªããšããããšã¯ãŸã£ãããããŸããã ããšãã°ãMipsã¢ãŒããã¯ãã£ã¯ãåºå®ãµã€ãºïŒ32ãããïŒã®ã¬ãžã¹ã¿ã§ã®ã¿ç®è¡æŒç®ãå®è¡ã§ããŸãã éåžž ã short intåã®ãµã€ãºã¯16ãããã§ã char -8ãããã§ãã ãããã®ã¿ã€ãã®ããããã®å€æ°ãã¬ãžã¹ã¿ãŒã«æ ŒçŽããããšããã®ãµã€ãºãæ¡å€§ãããããæ£ãã転éããããã«ãå°ãªããšã1ã€ã®è¿œå æäœãå®è¡ããå Žåã«ãã£ãŠã¯è¿œå ã®ã¬ãžã¹ã¿ãŒã䜿çšããå¿ èŠããããŸãïŒå¯Ÿå¿ããããããã¹ã¯ã«å¯Ÿå¿ããããïŒã é·ãéMipsã³ãŒããæ±ã£ãŠããªãããšãèªããããåŸãªãã®ã§ããããã®æäœã®æ£ç¢ºãªã³ã¹ãã«ã€ããŠã¯ããããŸãããããŒã以å€ã§ãããä»ã®RISCã¢ãŒããã¯ãã£ã§ãåãåé¡ãçºçããå¯èœæ§ããããšç¢ºä¿¡ããŠããŸãã
èšèªèŠæ Œã¯ãã¢ãŒããã¯ãã£ã§æå³ãããŠããå Žåãå€æ°è»¢éã®åé¿ãçŠæ¢ããŠããŸããïŒ
èŠããšããã®è°è«ã¯ç¹ã«åŒ±ãã§ãã ãã®æ¬è³ªã¯ãæšæºã«ãã£ãŠãå®è£ ïŒã³ã³ãã€ã©ïŒãéãããç¯å²ã§ã®ã¿ãäžå®ã®åäœãã解éã§ããããã«ããããšã§ãã èŠæ Œèªäœã®ããã¹ãã§-移転ã®æ¯æè ã蚎ãããã®æçã§-次ã®ããã«èšãããŠããŸãïŒããã¯ãäžå®è¡åããšããçšèªã®å®çŸ©ã®äžéšã§ãïŒïŒ
æ³šïŒ æªå®çŸ©ã®åäœã¯ãç¶æ³ãå®å šã«ç¡èŠãããšãã圢ããšãå ŽåããããŸãããçµæã¯äºæž¬äžå¯èœã§ã...
ãç¶æ³ãå®å šã«ç¡èŠããããšããèšèã¯ãæªå®çŸ©ã®åäœïŒããšãã°ãè¿œå äžã®ãªãŒããŒãããŒïŒã«ã€ãªããã€ãã³ããçºçããªãããšã瀺åããŠããã®ã§ã¯ãªããããããã§ããã°ãã³ã³ãã€ã©ã¯çºçããããšã¯ãããŸããããããã»ããµã«ãã®ãããªæäœãå®è¡ããèŠæ±ãéä¿¡ããå Žåã«çºçããçµæãèæ ®ããŸãïŒã€ãŸãããœãŒã¹ã³ãŒããåçŽã§çŽ æŽãªæ¹æ³ã§ãã·ã³ã³ãŒãã«å€æããããã®ããã«ïŒã
ãŸãããã®ããã¹ãã¯ãã¡ã¢ããšããŠäžããããŠãããããæšæºã®æŠèŠã§èšåãããŠããISOæ什ã«åŸã£ãŠãèŠç¯çã§ã¯ãªãïŒã€ãŸããäœããèŠå®ã§ããªãïŒããšã«æ³šæããå¿ èŠããããŸãã
ISO / IECæ什ã®ããŒã3ã«åŸã£ãŠããã®åºæãæ¬æã®çŽ¹ä»ãã¡ã¢ãè泚ãããã³äŸãæ å ±æäŸã®ã¿ãç®çãšããŠããŸãã
ãã®ãäžå®ã®åäœãã®äžç¯ã¯ã¡ã¢ã§ãããããäœãèŠå®ããŠããŸããã ãäžå®ã®åäœãã®çŸåšã®å®çŸ©ã¯æ¬¡ã®ãšããã§ãã
蚱容ã§ããªãããŸãã¯äžæ£ç¢ºãªãœãããŠã§ã¢èšèšãŸãã¯äžæ£ç¢ºãªããŒã¿ã®äœ¿çšã«èµ·å ããæ¯ãèãã ãã®åœéèŠæ Œã§ã¯èŠä»¶ã課ããŠããŸãã ã
ç§ã¯äž»ãªã¢ã€ãã¢ã匷調ããŸããïŒäžæ確ãªæ¯ãèãã«èŠä»¶ã¯èª²ãããŸããã 泚ã®ãå¯èœãªã¿ã€ãã®æªå®çŸ©ã®åäœãã®ãªã¹ãã«ã¯ãäŸã®ã¿ãå«ãŸããŠãããæçµçãªåŠæ¹ç®ã«ããããšã¯ã§ããŸããã ãã以å€ã®å ŽåããèŠæ±ãè¡ããªãããšãããã¬ãŒãºã¯è§£éã§ããŸããã
ãã®è°è«ãå±éããŠãããã¹ãã«é¢ä¿ãªããèšèªå§å¡äŒã¯ãããã®åèªãå®åŒåãããšããå šäœãšããŠã®åäœã¯ããã°ã©ã ãå®è¡ãããŠããããŒããŠã§ã¢ã®ã¢ãŒããã¯ãã£ã«å¯èœãªéã察å¿ããå¿ èŠããããšäž»åŒµããçŽ æŽãªç¿»èš³ãæ瀺ããŠããŸããã·ã³ã³ãŒãã«ã ããã¯çå®ãããããŸãããããã®è°è«ãæ¯æãã蚌æ ïŒäŸãã°ãæŽå²çææžïŒãèŠãããšã¯ãããŸããã ãã ããããšãããã§ãã£ããšããŠãããã®å£°æãããã¹ãã®çŸåšã®ããŒãžã§ã³ã«é©çšããããšããäºå®ã§ã¯ãããŸããã
æåŸã®èã
移転ãæ¯æããè°è«ã¯ã倧éšåãåãå ¥ããããªãã ãããããããããçµã¿åããããšãæã匷åãªè°è«ãåŸãããŸãïŒçµéšã®å°ãªãããã°ã©ããŒïŒCèšèªã®è€éããšãã®äžå®ã®åäœãç¥ããªãïŒã¯ã転éãæåŸ ããããšããããããã©ãŒãã³ã¹ãäœäžãããŸãã-åŸè ã¯ãã¹ãŠã®å Žåã«åœãŠã¯ãŸããŸããããæåã®éšåã¯æ±ºå®çã§ã¯ãããŸããåå¥ã«æ€èšããå Žåã
å人çã«ã¯ããªãŒããŒãããŒããããªãŒããŒãããŒããããã¯ïŒãã©ããã³ã°ïŒããã»ãã奜ãŸãããšæããŸãã ã€ãŸããããã°ã©ã ãã¯ã©ãã·ã¥ããåäœãç¶ç¶ããŸãã-ã©ã¡ãã®å Žåãè匱æ§ãçŸãããããäžç¢ºå®ãªåäœãŸãã¯æœåšçã«èª€ã£ãçµæãçºçããŸãã ãã¡ããããã®ãããªãœãªã¥ãŒã·ã§ã³ã¯ãã»ãšãã©ã®ïŒïŒïŒã¢ãŒããã¯ãã£ãç¹ã«x86ã§ããã©ãŒãã³ã¹ããããã«äœäžãããŸãããäžæ¹ã§ããªãŒããŒãããŒãšã©ãŒã¯ããã«ç¹å®ãããããããããã«äœ¿çšããŠãééã£ãçµæãååŸããããšã¯ã§ããŸããããã°ã©ã ã ããã«ãçè«çã«ã¯ããã®ã¢ãããŒãã䜿çšããã³ã³ãã€ã©ãŒã¯åé·ãªãªãŒããŒãããŒãã§ãã¯ãå®å šã«åé€ã§ããŸããããã¯ç¢ºãã«çºçããªãããã§ãããã ããClangãGCCããã®æ©äŒã䜿çšããŸããã
幞ããªããšã«ãå²ã蟌ã¿ãšç§»æ€ã®äž¡æ¹ããç§ãæãé »ç¹ã«äœ¿çšããã³ã³ãã€ã©ãŒã§ããGCCã«å®è£ ãããŠããŸãã ã¢ãŒããåãæ¿ããã«ã¯ããããã-ftrapvããã³-fwrapvã³ãã³ãã©ã€ã³åŒæ°ã䜿çšãããŸãã
ãã¡ãããæªå®çŸ©ã®åäœã«ã€ãªããå€ãã®ã¢ã¯ã·ã§ã³ããããŸã-æŽæ°ãªãŒããŒãããŒã¯ãããã®1ã€ã«ãããŸããã ãããã®ãã¹ãŠã®ã±ãŒã¹ãæªå®çŸ©ã®åäœãšããŠè§£éããããšã¯æçšã§ãããšã¯ãŸã£ããæããŸããããŸããèšèªã«ãã£ãŠã»ãã³ãã£ã¯ã¹ã決å®ãããããå°ãªããšãå®è£ ã®è£éã«å§ããããç¹å®ã®ç¶æ³ãå€ããããšç¢ºä¿¡ããŠããŸãã ã³ã³ãã€ã©ã¡ãŒã«ãŒã«ãããã®æŠå¿µã®é床ã«èªç±ãªè§£éãæãã®ã§ããã³ã³ãã€ã©ã®åäœãéçºè ãç¹ã«å人çã«æšæºã®ããã¹ããèªãã§ããéçºè ã®çŽæçãªã¢ã€ãã¢ã«åããªãå Žåãããã¯æ¬åœã®ãšã©ãŒã«ã€ãªããå¯èœæ§ããããŸãã ãã®å Žåã®çç£æ§ã®åäžãç¡èŠã§ããå Žåããã®ãããªè§£éãæŸæ£ããæ¹ãããã§ãããã 以äžã®æçš¿ã®ããããã§ããããã®åé¡ã®ããã€ããæ€èšããŸãã
ãµããªã¡ã³ãïŒ2018幎8æ24æ¥ä»ãïŒ
äžèšã®å€ããããè¯ãæžããããšã«æ°ã¥ããŸããã 以äžã«ãç§ã®èšèãç°¡åã«èŠçŽããŠèª¬æããããã€ãã®å°ããªã³ã¡ã³ããè¿œå ããŸãã
- ç§ã¯ãäžæ確ãªæ¯ãèãããªãŒããŒãããŒãéã¶ããã«å¥œãŸãããšäž»åŒµããŸããã§ãã-ãããã å®éã«ã¯ã転éã¯äžå®ã®æ¯ãèããããã¯ããã«åªããŠããŸãã ã ç¹ã«ãæåã®å Žåãš2çªç®ã®å Žåã«ã»ãã¥ãªãã£ã®åé¡ãçºçããå¯èœæ§ããããŸã-ãããŠãæéå ã«ææãããªãã£ããªãŒããŒãããŒã«ãã£ãŠåŒãèµ·ããããè匱æ§ã®å€ãã¯ïŒã³ã³ãã€ã©ã誀ã£ããã§ãã¯ãåé€ãã責任ããããã®ãé€ãïŒ -çµæã®è»¢éãåå ã§ããããªãŒããŒãããŒã«é¢é£ããæªå®çŸ©ã®åäœãåå ã§ã¯ãããŸããã
- 転éã®å¯äžã®æ¬åœã®å©ç¹ã¯ããªãŒããŒãããŒãã§ãã¯ãåé€ãããªãããšã§ãã ãã®æ¹æ³ã§ããã€ãã®æ»æã·ããªãªããã³ãŒããä¿è·ã§ããŸããããªãŒããŒãããŒã®äžéšã¯ãŸã£ãããã§ãã¯ãããªãïŒã€ãŸããããã°ã©ããŒããã®ãããªãã§ãã¯ãè¿œå ããã®ãå¿ããïŒããšã«æ°ä»ãããªãå¯èœæ§ããããŸãã
- ã»ãã¥ãªãã£ã®åé¡ãããã»ã©éèŠã§ã¯ãªããããã°ã©ã ã®é«éåãåé¢ã«åºãå Žåãæªå®çŸ©ã®åäœã¯ãå°ãªããšãããã€ãã®å Žåã§ãããæå©ãªæé©åãšçç£æ§ã®å€§å¹ ãªåäžããããããŸãã äžæ¹ãã»ãã¥ãªãã£ãæåã«æ¥ãå Žåã移æ€ã«ã¯è匱æ§ã䌎ããŸãã
- ã€ãŸããäžæã転éãæªå®çŸ©ã®åäœã®ãããããéžæããå Žåã転éã圹ç«ã€ã¿ã¹ã¯ã¯ã»ãšãã©ãããŸããã
- çºçãããªãŒããŒãããŒã®ãã§ãã¯ã«ã€ããŠã¯ãããããæ®ãããšã¯æ害ã§ãããšä¿¡ããŠããŸãã ãªãŒããŒãããŒãäžæãããšããã®åé¡ãåé¿ã§ããŸãã é©åãªèŠå-軜æžããŠãã ããã
- ã»ãã¥ãªãã£ã¯ãªãã£ã«ã«ãªã³ãŒããèšè¿°ããéçºè ã¯ããã®èœãšãç©Žã«æ³šæããã ãã§ãªããèšè¿°ããèšèªã®ã»ãã³ãã£ã¯ã¹ãååã«ç解ããŠããããšãçæ³çã§ãã Cã®å Žåãããã¯ããªãŒããŒãããŒã®ã»ãã³ãã£ã¯ã¹ãšæªå®çŸ©ã®åäœã®åŸ®åŠããç¥ãå¿ èŠãããããšãæå³ããŸãã äžéšã®ããã°ã©ããŒããã®ã¬ãã«ãŸã§æé·ããŠããªãã®ã¯æ²ããããšã§ãã
- ãã»ãšãã©ã®Cããã°ã©ããŒã¯ããã©ã«ãã®åäœãšããŠç§»è¡ãæåŸ ããŠããããšãã䞻匵ã«åºããããŸãããããã®èšŒæ ã¯ããããŸããã ïŒãã®èšäºã§ã¯ãå®éã®ç掻ããããã€ãã®äŸãç¥ã£ãŠããããããäžéšã®ããã°ã©ããŒããäœæããŸãããäžè¬çã«ã誰ããããã«åè«ããããšã¯ãªãã§ããããïŒ
- 2ã€ã®ç°ãªãåé¡ããããŸããCèšèªæšæºãèŠæ±ãããã®ãšãã³ã³ãã€ã©ãŒãå®è£ ãã¹ããã®ã§ãã ç§ã¯ïŒäžè¬ã«ïŒæšæºãæªå®çŸ©ã®ãªãŒããŒãããŒåäœãå®çŸ©ããæ¹æ³ã奜ãã§ãã ãã®æçš¿ã§ã¯ãã³ã³ãã€ã©ãŒããã¹ãããšã«ã€ããŠè©±ããŠããŸãã
- ãªãŒããŒãããŒãäžæãããå Žåããã¹ãŠã®æäœããã§ãã¯ããå¿ èŠã¯ãããŸããã çæ³çã«ã¯ããã®ã¢ãããŒãã䜿çšããããã°ã©ã ã¯ãæ°åŠçãªèŠåã«é¢ããŠäžè²«ããŠåäœããããåäœãåæ¢ããŸãã ãã®å ŽåããäžæçãªãªãŒããŒãããŒãã®ååšãå¯èœã«ãªãã誀ã£ãçµæã衚瀺ãããããšã¯ãããŸããã 次ã«ãåŒa + b-bãšåŒïŒa * bïŒ/ bã®äž¡æ¹ãaã«æé©åã§ããŸãïŒåè ã転éäžã«å¯èœã§ãããåŸè ã¯ãã¯ãååšããŸããïŒã
ã泚æ èšäºã®ç¿»èš³ã¯ãèè ã®èš±å¯ãåŸãŠããã°ã«å ¬éãããŠããŸãã å ã®ããã¹ãïŒDavin McCallã æŽæ°ãªãŒããŒãããŒã§ã©ããããããšã¯ãå§ãã§ããŸãã ãã
PVS-StudioããŒã ããã®è¿œå ã®é¢é£ãªã³ã¯ïŒ
- ã¢ã³ãã¬ã€ã»ã«ã«ããã æªå®çŸ©ã®æ¯ãèãã¯ãããªããèãããããè¿ãã§ã ã
- Will DietzãPeng LiãJohn RegehrãVikram Adveã C / C ++ã®æŽæ°ãªãŒããŒãããŒãç解ãã ã
- V1026ã å€æ°ã¯ã«ãŒãå ã§ã€ã³ã¯ãªã¡ã³ããããŸãã 笊å·ä»ãæŽæ°ãªãŒããŒãããŒã®å Žåãæªå®çŸ©ã®åäœãçºçããŸãã
- Stackoverflow C ++ã§ã¯ç¬Šå·ä»ãæŽæ°ãªãŒããŒãããŒã¯æªå®çŸ©ã®åäœã§ããïŒ