C ¥æ¡¼¥¶¡¼¥º¥¬¥¤¥É ¥Û¡¼¥àÌܼ¡Á°¥Ú¡¼¥¸¤Ø¼¡¥Ú¡¼¥¸¤Øº÷°ú


Âè 7 ¾Ï

ANSI/ISO C ¤Ø¤Î°Ü¹Ô

¤³¤Î¾Ï¤ÎÆâÍƤϡ¢¼¡¤Î¤È¤ª¤ê¤Ç¤¹¡£

´ðËܥ⡼¥É

ANSI/ISO C ¥³¥ó¥Ñ¥¤¥é¤Ç¤Ï¡¢¸Å¤¤·Á¼°¤È¿·¤·¤¤·Á¼°¤ÎξÊý¤Î C ¥³¡¼¥É¤ò»ÈÍѤǤ­¤Þ¤¹¡£¼¡¤Î -X (Âçʸ»ú¤Î X ¤Ç¤¢¤ë¤³¤È¤ËÃí°Õ) ¥ª¥×¥·¥ç¥ó¤Ï ANSI/ISO C µ¬³Ê¤Ø¤Î½àµò¤ÎÅٹ礤¤ò»ØÄꤷ¤Þ¤¹¡£¥Ç¥Õ¥©¥ë¥È¤Î¥â¡¼¥É¤Ï -Xa ¤Ç¤¹¡£

-Xa

(a = ANSI) ANSI/ISO C ¤Ë K&R C ¤È¤Î³ÈÄ¥¸ß´¹À­¤ò»ý¤¿¤»¤Þ¤¹¡£ANSI/ISO C ¤Ë½¾¤Ã¤Æ°ÕÌ£²ò¼á¤òÊѹ¹¤·¤Þ¤¹¡£Æ±¤¸¸À¸ì¹½Â¤¤ËÂФ·¤Æ K&R C ¤È ANSI/ISO C ¤Î°ÕÌ£²ò¼á¤¬°Û¤Ê¤ë¾ì¹ç¤Ï¡¢Áê°ã¤Ë´Ø¤¹¤ë·Ù¹ð¤òȯ¹Ô¤·¤¿¾å¤Ç¡¢ANSI/ISO C ¤Ë½àµò¤·¤¿²ò¼á¤ò¹Ô¤¤¤Þ¤¹¡£¤³¤ì¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥â¡¼¥É¤Ç¤¹¡£

-Xc

(c = conformance) ANSI/ISO C ¤ËºÇÂç¸Â¤Ë½àµò¤·¤Þ¤¹¡£K&R C ¤È¤Î³ÈÄ¥¸ß´¹À­¤Ï¤¢¤ê¤Þ¤»¤ó¡£ANSI/ISO C ¤Ë¤Ê¤¤¹½Ê¸¤ò»ÈÍѤ·¤Æ¤¤¤ë¥×¥í¥°¥é¥à¤ËÂФ·¤Æ¡¢¥¨¥é¡¼¤È·Ù¹ð¤òȯ¹Ô¤·¤Þ¤¹¡£

-Xs

(s = K&R C) ¥³¥ó¥Ñ¥¤¥ë¤·¤¿¸À¸ì¤Ë¤Ï¡¢ANSI °ÊÁ°¤Î K&R C ¤È¸ß´¹À­¤ò»ý¤Ä¤¹¤Ù¤Æ¤Îµ¡Ç½¤¬´Þ¤Þ¤ì¤Þ¤¹¡£ANSI/ISO C ¤È K&R C ¤Î´Ö¤ÇÆ°ºî¤¬°Û¤Ê¤ë¤¹¤Ù¤Æ¤Î¸À¸ì¹½Ê¸¤ËÂФ·¤Æ¡¢·Ù¹ð¤òȯ¹Ô¤·¤Þ¤¹¡£

-Xt

(t = transition) ANSI/ISO C ¤Ë K&R C ¤È¤Î³ÈÄ¥¸ß´¹À­¤ò»ý¤¿¤»¤Þ¤¹¡£ANSI/ISO C ¤Ë½¾¤Ã¤¿°ÕÌ£²ò¼á¤ÎÊѹ¹¤Ï¹Ô¤¤¤Þ¤»¤ó¡£Æ±¤¸¹½Ê¸¤ËÂФ·¤Æ K&R C ¤È ANSI/ISO C ¤Î°ÕÌ£²ò¼á¤¬°Û¤Ê¤ë¾ì¹ç¤Ï¡¢Áê°ã¤Ë´Ø¤¹¤ë·Ù¹ð¤òȯ¹Ô¤·¤¿¾å¤Ç¡¢K&R C ¤Ë½àµò¤·¤¿²ò¼á¤ò¹Ô¤¤¤Þ¤¹¡£

¸Å¤¤·Á¼°¤Î´Ø¿ô¤È¿·¤·¤¤·Á¼°¤Î´Ø¿ô¤ÎÊ»ÍÑ

ANSI/ISO C ¤Ç¤ÎºÇÂç¤ÎÊѹ¹ÅÀ¤Ï¡¢C++ ¸À¸ì¤Îµ¡Ç½¤Ç¤¢¤ë´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤ò»ÈÍѤǤ­¤ë¤³¤È¤Ç¤¹¡£³Æ´Ø¿ô¤Ë¥Ñ¥é¥á¡¼¥¿¤Î¿ô¤È·¿¤ò»ØÄꤹ¤ë¤³¤È¤Ë¤è¤ê¡¢¤¹¤Ù¤Æ¤ÎÄ̾ï¤Î¥³¥ó¥Ñ¥¤¥ë¤Ë¤ª¤¤¤Æ¡¢´Ø¿ô¸Æ¤Ó½Ð¤·¤´¤È¤Ë (lint ¤Î¤è¤¦¤Ë) °ú¿ô¤È¥Ñ¥é¥á¡¼¥¿¤¬¸¡ºº¤µ¤ì¤ë¤À¤±¤Ç¤Ï¤Ê¤¯¡¢°ú¿ô¤¬ (ÂåÆþ¤À¤±¤Ç) ¼«Æ°Åª¤Ë´Ø¿ô¤¬´üÂÔ¤¹¤ë·¿¤ËÊÑ´¹¤µ¤ì¤Þ¤¹¡£¥×¥í¥È¥¿¥¤¥×¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÊѹ¹¤Ç¤­¤ë (¤Þ¤¿¡¢Êѹ¹¤¹¤Ù¤­) ´û¸¤Î C ¥³¡¼¥É¤¬Èó¾ï¤Ë¿¤¯Â¸ºß¤¹¤ë¤¿¤á¡¢ANSI/ISO C ¤Ë¤Ï¡¢¸Å¤¤·Á¼°¤È¿·¤·¤¤·Á¼°¤Î´Ø¿ôÀë¸À¤òÊ»ÍѤ¹¤ëµ¬Â§¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£

¿·¤·¤¤¥³¡¼¥É¤ò½ñ¤¯

¤Þ¤Ã¤¿¤¯¿·¤·¤¤¥×¥í¥°¥é¥à¤ò½ñ¤¯¤È¤­¡¢¥Ø¥Ã¥À¡¼¤Ç¤Ï¡¢¿·¤·¤¤·Á¼°¤Î´Ø¿ôÀë¸À (´Ø¿ô¥×¥í¥È¥¿¥¤¥×) ¤ò»ÈÍѤ·¡¢¤½¤ì°Ê³°¤Î C ¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤Ç¤Ï¡¢¿·¤·¤¤·Á¼°¤Î´Ø¿ôÀë¸À¤È´Ø¿ôÄêµÁ¤ò»ÈÍѤ·¤Þ¤¹¡£¤·¤«¤·¡¢ANSI/ISO C °ÊÁ°¤Î¥³¥ó¥Ñ¥¤¥é¤ò»ý¤Ä¥Þ¥·¥ó¤Ë¥³¡¼¥É¤ò°Ü¿¢¤¹¤ë²ÄǽÀ­¤¬¤¢¤ë¾ì¹ç¤Ï¡¢¥Ø¥Ã¥À¡¼¤È¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤ÎξÊý¤Ç¡¢¥Þ¥¯¥í __STDC__ (ANSI/ISO C ¥³¥ó¥Ñ¥¤¥ë¥·¥¹¥Æ¥àÀìÍѤËÄêµÁ¤µ¤ì¤Æ¤¤¤ë) ¤ò»ÈÍѤ¹¤ë¤³¤È¤ò¤ª´«¤á¤·¤Þ¤¹¡£Îã¤Ë¤Ä¤¤¤Æ¤Ï¡¢¡ÖÊ»ÍѤ˴ؤ¹¤ë¹ÍθÅÀ¡×¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£

Ʊ¤¸¥ª¥Ö¥¸¥§¥¯¥È¤Þ¤¿¤Ï´Ø¿ô¤ËÂФ·¤Æ 2 ¤Ä¤Î¸ß´¹À­¤Î¤Ê¤¤Àë¸À¤¬Æ±¤¸¥¹¥³¡¼¥×¤ÎÃæ¤Ë¤¢¤ë¾ì¹ç¡¢ANSI/ISO C ½àµò¤Î¥³¥ó¥Ñ¥¤¥é¤Ï¿ÇÃÇ¥á¥Ã¥»¡¼¥¸¤òȯ¹Ô¤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤¹¤Ù¤Æ¤Î´Ø¿ô¤¬¥×¥í¥È¥¿¥¤¥×¤ÇÀë¸À¤ª¤è¤ÓÄêµÁ¤µ¤ì¡¢Å¬ÀڤʥإåÀ¡¼¤¬Àµ¤·¤¤¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤Ë¥¤¥ó¥¯¥ë¡¼¥É¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¤¹¤Ù¤Æ¤Î¸Æ¤Ó½Ð¤·¤Ï´Ø¿ô¤ÎÄêµÁ¤Ë½¾¤¦¤Ï¤º¤Ç¤¹¡£¤³¤Î¼è¤ê·è¤á¤Ë¤è¤Ã¤Æ¡¢¤â¤Ã¤È¤â¤¢¤ê¤¬¤Á¤Ê C ¥×¥í¥°¥é¥ß¥ó¥°¤Î¸í¤ê¤òËɤ°¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

´û¸¤Î¥³¡¼¥É¤ò¹¹¿·¤¹¤ë

´û¸¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤òÍøÍѤ·¤¿¤¤¾ì¹ç¡¢¤É¤ì¤¯¤é¤¤¤Î¥³¡¼¥É¤òÊѹ¹¤¹¤ë¤«¤Ë¤è¤Ã¤Æ¡¢¹¹¿·ÊýË¡¤¬°Û¤Ê¤ê¤Þ¤¹¡£

1. Êѹ¹¤»¤º¤ËºÆ¥³¥ó¥Ñ¥¤¥ë¤¹¤ë

¥³¡¼¥É¤òÊѹ¹¤·¤Ê¤¯¤Æ¤â¡¢-v ¥ª¥×¥·¥ç¥ó¤Ç¥³¥ó¥Ñ¥¤¥é¤ò¼Â¹Ô¤¹¤ë¤È¡¢¥Ñ¥é¥á¡¼¥¿¤Î·¿¤È¿ô¤ÎÉÔ°ìÃפˤĤ¤¤Æ·Ù¹ð¤¬È¯¹Ô¤µ¤ì¤Þ¤¹¡£

2. ¥Ø¥Ã¥À¡¼¤À¤±¤Ë´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤òÄɲ乤ë

Âç°èŪ¤Ê´Ø¿ô¤Ø¤Î¤¹¤Ù¤Æ¤Î¸Æ¤Ó½Ð¤·¤¬¿ÇÃǤÎÂоݤˤʤê¤Þ¤¹¡£

3. ¥Ø¥Ã¥À¡¼¤Ë¤Ï´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤òÄɲä·¡¢³Æ¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë¤Ï¶É½ê (ÀÅŪ¤Ê) ´Ø¿ô¤ËÂФ¹¤ë´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤òÄɲ乤ë

´Ø¿ô¤Ø¤Î¤¹¤Ù¤Æ¤Î¸Æ¤Ó½Ð¤·¤¬¿ÇÃǤÎÂоݤˤʤê¤Þ¤¹¡£¤¿¤À¤·¤³¤ÎÊýË¡¤Ç¤Ï¡¢¥½¡¼¥¹¥Õ¥¡¥¤¥ëÆâ¤Ç¶É½ê´Ø¿ô¤´¤È¤Ë 2 ²ó¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤òÆþÎϤ¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£

4. ¤¹¤Ù¤Æ¤Î´Ø¿ôÀë¸À¤È´Ø¿ôÄêµÁ¤ò¡¢´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÊѹ¹¤¹¤ë

·ë²Ì¤È¤·¤Æ¼õ¤±¤ë²¸·Ã¤È¤½¤Î¤¿¤á¤ÎÉé²Ù¤ò¹Í¤¨¤ë¤È¡¢¤Û¤È¤ó¤É¤Î¾ì¹ç¡¢¾åµ­¤Î 2 ¤« 3 ¤¬Å¬ÀÚ¤ÊÁªÂò¤À¤È¸À¤¨¤ë¤Ç¤·¤ç¤¦¡£¤¿¤À¤·¤³¤ì¤é¤òÁªÂò¤¹¤ë¾ì¹ç¡¢¸Å¤¤·Á¼°¤È¿·¤·¤¤·Á¼°¤òÊ»ÍѤ¹¤ë¤¿¤á¤Îµ¬Â§¤ò¾ÜºÙ¤ËÃΤäƤª¤¯É¬Íפ¬¤¢¤ê¤Þ¤¹¡£

Ê»ÍѤ˴ؤ¹¤ë¹ÍθÅÀ

´Ø¿ô¥×¥í¥È¥¿¥¤¥×Àë¸À¤È¸Å¤¤·Á¼°¤Î´Ø¿ôÄêµÁ¤¬¤È¤â¤Ëµ¡Ç½¤¹¤ë¤¿¤á¤Ë¤Ï¡¢Î¾Êý¤¬µ¡Ç½Åª¤ËƱ¤¸¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤Ä¤Þ¤ê¡¢ANSI/ISO C ¤ÎÍѸì¤ò»ÈÍѤ¹¤ë¡Ö¸ß´¹·Á¼°¡×¤ò»ý¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£

²ÄÊÑ°ú¿ô¤ò»ý¤Ä´Ø¿ô¤Î¾ì¹ç¤Ï¡¢ANSI/ISO C ¤Î¾Êάµ­¹æ¤È¸Å¤¤·Á¼°¤Î varargs() ´Ø¿ôÄêµÁ¤òÊ»ÍѤ¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£¸ÇÄê¿ô¤Î¥Ñ¥é¥á¡¼¥¿¤ò»ý¤Ä´Ø¿ô¤Î¾ì¹ç¡¢°ÊÁ°¤Î¼ÂÁõ¤ÇÅϤ·¤¿¤È¤ª¤ê¤Î¥Ñ¥é¥á¡¼¥¿¤Î·¿¤ò»ØÄꤹ¤ë¤À¤±¤Ç¤¹¡£

K&R C ¤Ç¤Ï¡¢³Æ°ú¿ô¤Ï¡¢¸Æ¤Ó½Ð¤µ¤ì¤¿´Ø¿ô¤ËÅϤµ¤ì¤ëľÁ°¤Ë¡¢¥Ç¥Õ¥©¥ë¥È¤Î°ú¿ô³ÈÄ¥¤Ë½¾¤Ã¤ÆÊÑ´¹¤µ¤ì¤Þ¤·¤¿¡£¤³¤Î¤è¤¦¤Ê³ÈÄ¥¤Ç¤Ï¡¢int ¤è¤ê¶¹¤¤¤¹¤Ù¤Æ¤ÎÀ°¿ô·¿¤ò int ¥µ¥¤¥º¤Ë³ÈÄ¥¤·¡¢¤Þ¤¿¡¢Ç¤°Õ¤Î float °ú¿ô¤ò double ¤Ë³ÈÄ¥¤¹¤ë¤è¤¦¤Ë»ØÄꤵ¤ì¤Æ¤¤¤¿¤¿¤á¡¢¥³¥ó¥Ñ¥¤¥é¤È¥é¥¤¥Ö¥é¥ê¤ÎξÊý¤¬Ã±½ã²½¤µ¤ì¤Æ¤¤¤Þ¤·¤¿¡£´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤ò»ÈÍѤ¹¤ë¤È¡¢¤è¤ê¤ï¤«¤ê¤ä¤¹¤¯É½¸½¤Ç¤­¤Þ¤¹¡£¤Ä¤Þ¤ê¡¢»ØÄꤷ¤¿¥Ñ¥é¥á¡¼¥¿¤Î·¿¤¬¡¢¤½¤Î¤Þ¤Þ¡¢´Ø¿ô¤ËÅϤµ¤ì¤ë¥Ñ¥é¥á¡¼¥¿¤Î·¿¤È¤Ê¤ê¤Þ¤¹¡£

¤·¤¿¤¬¤Ã¤Æ¡¢´û¸¤Î (¸Å¤¤·Á¼°¤Î) ´Ø¿ôÄêµÁÍѤ˴ؿô¥×¥í¥È¥¿¥¤¥×¤ò½ñ¤¯¾ì¹ç¡¢´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤Ë¼¡¤Î·¿¤Î¥Ñ¥é¥á¡¼¥¿¤Ï»ÈÍѤǤ­¤Þ¤»¤ó¡£

char
signed char
unsigned char
float
short
signed short
unsigned short


¥×¥í¥È¥¿¥¤¥×¤ò½ñ¤¯ºÝ¤Ë¤Ï¡¢¤µ¤é¤Ë 2 ¤Ä¤ÎÌäÂ꤬¤¢¤ê¤Þ¤¹¡£typedef ̾¤È¡¢¶¹¤¤ unsigned ·¿¤Î³ÈÄ¥µ¬Â§¤Ç¤¹¡£

¸Å¤¤·Á¼°¤Î´Ø¿ôÆâ¤Î¥Ñ¥é¥á¡¼¥¿¤¬ typedef ̾¤ÇÀë¸À¤µ¤ì¤Æ¤¤¤ë¾ì¹ç (off_t ¤ä ino_t ¤Ê¤É)¡¢typedef ̾¤¬¥Ç¥Õ¥©¥ë¥È¤Î°ú¿ô³ÈÄ¥¤Ë¤è¤Ã¤Æ±Æ¶Á¤ò¼õ¤±¤ë·¿¤ò»Ø¤·¤Æ¤¤¤ë¤«¤É¤¦¤«¤ò³Îǧ¤¹¤ë¤³¤È¤¬½ÅÍפǤ¹¡£¾åµ­ 2 ¤Ä¤Î typedef ̾ ¤òÎã¤Ë¤¹¤ë¤È¡¢off_t ¤Ï long ¤Ç¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤Ç»ÈÍѤ¹¤ë¤³¤È¤ÏŬÀڤʻÈÍÑÊýË¡¤Ç¤¹¡£¤·¤«¤·¡¢ino_t ¤Ï unsigned short ¤Ç¤¢¤Ã¤¿¤¿¤á¡¢¥×¥í¥È¥¿¥¤¥×¤Ç»ÈÍѤ¹¤ë¤È¡¢¸Å¤¤·Á¼°¤ÎÄêµÁ¤È¥×¥í¥È¥¿¥¤¥×¤¬°Û¤Ê¤ë¸ß´¹À­¤Î¤Ê¤¤¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò»ØÄꤹ¤ë¤¿¤á¡¢¿ÇÃÇ¥á¥Ã¥»¡¼¥¸¤¬È¯¹Ô¤µ¤ì¤Þ¤¹¡£

ºÇ¸å¤ÎÌäÂê¤Ï¡¢unsigned short ¤ÎÂå¤ï¤ê¤Ë²¿¤ò»ÈÍѤ¹¤ë¤«¤Ç¤¹¡£K&R C ¤È ANSI/ISO C ¥³¥ó¥Ñ¥¤¥é´Ö¤ÎºÇÂç¤ÎÈó¸ß´¹À­¤Î 1 ¤Ä¤Ï¡¢unsigned char ¤È unsigned short ¤ò int Ãͤ˹­¤²¤ë¤¿¤á¤Î³ÈÄ¥µ¬Â§¤Ç¤¹ (¡Ö³ÈÄ¥: Éä¹æ¤Ê¤·Êݸ¤ÈÃͤÎÊÝ»ý¡×¤ò»²¾È)¡£¤³¤Î¤è¤¦¤Ê¸Å¤¤·Á¼°¤Î¥Ñ¥é¥á¡¼¥¿¤Ë¤¢¤¿¤ë·¿¤Ï¡¢¥³¥ó¥Ñ¥¤¥ë»þ¤Ë»ÈÍѤ¹¤ë¥³¥ó¥Ñ¥¤¥ë¥â¡¼¥É¤Ë¤è¤Ã¤Æ°Û¤Ê¤ê¤Þ¤¹¡£

ºÇÎɤÎÊýË¡¤Ï¡¢int ¤Þ¤¿¤Ï unsigned int ¤Î¤É¤Á¤é¤«¤ò»ØÄꤹ¤ë¤è¤¦¤Ë¸Å¤¤·Á¼°¤ÎÄêµÁ¤òÊѹ¹¤·¤Æ¡¢°ìÃפ¹¤ë·¿¤ò´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤Ç»ÈÍѤ¹¤ë¤³¤È¤Ç¤¹¡£É¬ÍפǤ¢¤ì¤Ð¡¢´Ø¿ô¤òÆþÎϤ·¤¿¸å¤Ç¤â¡¢¤è¤ê¶¹¤¤·¿¤ÎÃͤò¶É½êÊÑ¿ô¤ËÂåÆþ¤Ç¤­¤Þ¤¹¡£

Á°½èÍý¤Ë¤è¤Ã¤Æ±Æ¶Á¤ò¼õ¤±¤ë²ÄǽÀ­¤Î¤¢¤ë¥×¥í¥È¥¿¥¤¥×¤Ç¤Ï¡¢ID ¤Î»ÈÍѤ˵¤¤ò¤Ä¤±¤Æ¤¯¤À¤µ¤¤¡£¼¡¤ÎÎã¤ò¹Í¤¨¤Æ¤¯¤À¤µ¤¤¡£

#define status 23
void my_exit(int status); * Ä̾¥¹¥³¡¼¥×¤Ï¥×¥í¥È¥¿¥¤¥×¤Ç»Ï¤Þ¤ê¡¢*/
/* ¥×¥í¥È¥¿¥¤¥×¤Ç½ª¤ï¤ë */


´Ø¿ô¥×¥í¥È¥¿¥¤¥×¤Ï¡¢¶¹¤¤·¿¤ò»ý¤Ä¸Å¤¤·Á¼°¤Î´Ø¿ôÄêµÁ¤ÈÊ»ÍѤǤ­¤Þ¤»¤ó¡£

void foo(unsigned char, unsigned short);
void foo(i, j) unsigned char i; unsigned short j; {...}


__STDC__ ¤òŬÀڤ˻ÈÍѤ¹¤ì¤Ð¡¢¸Å¤¤¥³¥ó¥Ñ¥¤¥é¤È¿·¤·¤¤¥³¥ó¥Ñ¥¤¥é¤ÎξÊý¤Ç»ÈÍѤǤ­¤ë¥Ø¥Ã¥À¡¼¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤­¤Þ¤¹¡£

header.h: 
    struct s { /* .  .  .  */ };
    #ifdef __STDC__ 
       void errmsg(int, ...);
       struct s *f(const char *);
       int g(void);
    #else 
      void errmsg();
      struct s *f();
      int g();
    #endif


¼¡¤Î´Ø¿ô¤Ï¥×¥í¥È¥¿¥¤¥×¤ò»ÈÍѤ·¤Æ¤¤¤Þ¤¹¤¬¡¢¸Å¤¤¥·¥¹¥Æ¥à¤Ç¤â¥³¥ó¥Ñ¥¤¥ë¤Ç¤­¤Þ¤¹¡£

struct s * 
#ifdef __STDC__
    f(const char *p)
#else 
    f(p) char *p;
#endif 
{
    /* .  .  .  */
}


¼¡¤ÎÎã¤Ï¡¢¹¹¿·¤·¤¿¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤Ç¤¹ (ÁªÂò»è 3 ¤ò»ÈÍѤ·¤¿¤â¤Î)¡£¶É½ê´Ø¿ô¤Ï¸Å¤¤·Á¼°¤ÎÄêµÁ¤ò»ÈÍѤ·¤Æ¤¤¤Þ¤¹¤¬¡¢¿·¤·¤¤¥³¥ó¥Ñ¥¤¥éÍѤ˥ץí¥È¥¿¥¤¥×¤â´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£

source.c:
   #include "header.h"
      typedef /* .  .  .  */ MyType;
   #ifdef __STDC__
      static void del(MyType *);
      /* .  .  .  */
      static void
      del(p) 
      MyType *p;
      { 
      /* .  .  .  */ 
      }
      /* .  .  .  */


²ÄÊÑ°ú¿ô¤ò»ý¤Ä´Ø¿ô

°ÊÁ°¤Î¼ÂÁõ¤Ç¤Ï¡¢´Ø¿ô¤¬´üÂÔ¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Î·¿¤ò»ØÄê¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£¤·¤«¤·¡¢ANSI/ISO C ¤Ç¥×¥í¥È¥¿¥¤¥×¤ò»ÈÍѤ¹¤ì¤Ð¡¢¤³¤ì¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£printf() ¤Ê¤É¤Î´Ø¿ô¤ò¥µ¥Ý¡¼¥È¤¹¤ë¤¿¤á¤Ë¡¢¥×¥í¥È¥¿¥¤¥×¤Î¹½Ê¸¤Ç¤ÏÆÃÊ̤ʾÊάµ­¹æ (...) ¤¬½ªÎ»¤ò¼¨¤¹µ­¹æ¤È¤·¤Æ»ÈÍѤµ¤ì¤Þ¤¹¡£¼ÂÁõ¤Ë¤è¤Ã¤Æ¤Ï²ÄÊÑ°ú¿ô¤ò½èÍý¤¹¤ë¤¿¤á¤ËÆÃÊ̤ʤ³¤È¤ò¹Ô¤¦É¬Íפ¬¤¢¤ë¤¿¤á¡¢ANSI/ISO C ¤Ç¤Ï¡¢¤¹¤Ù¤Æ¤ÎÀë¸À¤È¤³¤Î¤è¤¦¤Ê´Ø¿ô¤Ê¤É¤ÎÄêµÁ¤¬ËöÈø¤Ë¾Êάµ­¹æ¤ò´Þ¤à¤Ù¤­¤Ç¤¢¤ë¤Èµ¬Äꤷ¤Æ¤¤¤Þ¤¹¡£

¥Ñ¥é¥á¡¼¥¿¤Î¡Ö...¡×Éôʬ¤Ë¤Ï̾Á°¤¬¤Ê¤¤¤¿¤á¡¢stdarg.h ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ëÆÃÊ̤ʥޥ¯¥í¤Ë¤Ï¤³¤ì¤é¤Î°ú¿ô¤Ø¥¢¥¯¥»¥¹¤¹¤ë¤¿¤á¤Î´Ø¿ô¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£½é´ü¤Î¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï¤³¤Î¤è¤¦¤Ê´Ø¿ô¤Ï varargs.h ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ëƱÍͤʥޥ¯¥í¤ò»ÈÍѤ·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¤Ç¤·¤¿¡£

¼¡¤Ë¡¢¤³¤ì¤«¤é½ñ¤³¤¦¤È¤¹¤ë´Ø¿ô¤¬ errmsg() ¤È¤¤¤¦¥¨¥é¡¼¥Ï¥ó¥É¥é¤Ç¤¢¤ë¤È²¾Äꤷ¤Þ¤¹¡£¤³¤Î´Ø¿ô¤Ï void ¤òÊÖ¤·¡¢¸ÇÄê¥Ñ¥é¥á¡¼¥¿¤È¤·¤Æ¡¢¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤Î¾ÜºÙ¤ò»ØÄꤹ¤ë int ¤À¤±¤ò»ý¤Ä¤È²¾Äꤷ¤Þ¤¹¡£¤³¤Î¥Ñ¥é¥á¡¼¥¿¤Î¸å¤Ë¤Ï¡¢¥Õ¥¡¥¤¥ë̾¤Þ¤¿¤Ï¹ÔÈÖ¹æ (¤¢¤ë¤¤¤Ï¡¢¤½¤ÎξÊý) ¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£¤½¤·¤Æ¡¢¥Õ¥¡¥¤¥ë̾¤Þ¤¿¤Ï¹ÔÈÖ¹æ¤Î¸å¤Ë¤Ï¡¢(printf() ¤Î¤è¤¦¤Ê) ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤Î¥Æ¥­¥¹¥È¤ò»ØÄꤹ¤ë½ñ¼°¤È°ú¿ô¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£

½é´ü¤Î¥³¥ó¥Ñ¥¤¥é¤Ç¾åµ­Îã¤ò¥³¥ó¥Ñ¥¤¥ë¤¹¤ë¤Ë¤Ï¡¢ANSI/ISO C ¥³¥ó¥Ñ¥¤¥ë¥·¥¹¥Æ¥àÀìÍѤËÄêµÁ¤µ¤ì¤¿¥Þ¥¯¥í __STDC__ ¤ò¿¤¯»ÈÍѤ¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢Å¬ÀڤʥإåÀ¡¼¥Õ¥¡¥¤¥ë¤Ë¤ª¤±¤ë´Ø¿ô¤ÎÀë¸À¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£

#ifdef __STDC__
void errmsg(int code, ...);
#else
void errmsg();
#endif


errmsg() ¤ÎÄêµÁ¤ò»ý¤Ä¥Õ¥¡¥¤¥ë¤Ï¡¢¸Å¤¤·Á¼°¤È¿·¤·¤¤·Á¼°¤òÊ»ÍѤǤ­¤Þ¤¹¡£¤Þ¤º¡¢¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¥Ø¥Ã¥À¡¼¤Ï¥³¥ó¥Ñ¥¤¥ë¥·¥¹¥Æ¥à¤Ë¤è¤Ã¤Æ°Û¤Ê¤ê¤Þ¤¹¡£

#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <stdio.h>


¤½¤Î¸å¤Ç fprintf() ¤È vfprintf() ¤ò¸Æ¤Ó½Ð¤¹¤¿¤á¡¢stdio.h ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤¤¤Þ¤¹¡£

¼¡¤Ï´Ø¿ô¤ÎÄêµÁ¤Ç¤¹¡£¼±ÊÌ»Ò va_alist ¤È va_dcl ¤Ï¸Å¤¤·Á¼°¤Î varargs.h ¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Î°ìÉô¤Ç¤¹¡£

void
#ifdef __STDC__
errmsg(int code, ...)
#else
errmsg(va_alist) va_dcl /* Ãí: ¥»¥ß¥³¥í¥ó¤Ê¤· */
#endif
{
/* more detail below */
}


¸Å¤¤·Á¼°¤ÎÊÑ¿ô°ú¿ô¥á¥«¥Ë¥º¥à¤Ç¤Ï¸ÇÄê¥Ñ¥é¥á¡¼¥¿¤ò»ØÄê¤Ç¤­¤Ê¤¤¤¿¤á¡¢¸ÇÄê¥Ñ¥é¥á¡¼¥¿¤Ï¡¢²ÄÊÑÉôʬ¤ÎÁ°¤Ç¥¢¥¯¥»¥¹¤µ¤ì¤ë¤è¤¦¤ËÇÛÃÖ¤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤Þ¤¿¡¢¥Ñ¥é¥á¡¼¥¿¤Î¡Ö...¡×Éôʬ¤Ë̾Á°¤¬¤Ê¤¤¤¿¤á¡¢¿·¤·¤¤ va_start() ¥Þ¥¯¥í¤Ï 2 ÈÖÌܤΰú¿ô (¡Ö...¡×¤ÎľÁ°¤Ë¤¢¤ë¥Ñ¥é¥á¡¼¥¿¤Î̾Á°) ¤ò»ý¤Á¤Þ¤¹¡£

³ÈÄ¥¤È¤·¤Æ¡¢Sun ANSI/ISO C ¤Ç¤Ï¡¢¸ÇÄê¥Ñ¥é¥á¡¼¥¿¤Ê¤·¤Ç´Ø¿ô¤òÀë¸À¤ª¤è¤ÓÄêµÁ¤Ç¤­¤Þ¤¹¡£

 int f(...); 

¤³¤Î¤è¤¦¤Ê´Ø¿ô¤Î¾ì¹ç¡¢va_start() ¤Ï 2 ÈÖÌܤΰú¿ô¤ò¶õ¤Ë¤·¤Æ¸Æ¤Ó½Ð¤¹É¬Íפ¬¤¢¤ê¤Þ¤¹¡£

 va_start(ap,) 

¼¡¤Ï´Ø¿ô¤ÎËÜÂΤǤ¹¡£

{
va_list ap;
char *fmt;
#ifdef __STDC__
va_start(ap, code);
#else
int code;

va_start(ap);
/* ¸ÇÄê°ú¿ô¤òÃê½Ð¤¹¤ë */
code = va_arg(ap, int);
#endif
if (code & FILENAME)
(void)fprintf(stderr, "\"%s\": ", va_arg(ap, char *));
if (code & LINENUMBER)
(void)fprintf(stderr, "%d: ", va_arg(ap, int));
if (code & WARNING)
(void)fputs("warning: ", stderr);
fmt = va_arg(ap, char *);
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
}


va_arg() ¤È va_end() ¥Þ¥¯¥í¤ÏξÊý¤È¤â¸Å¤¤·Á¼°¤È ANSI/ISO C ¥Ð¡¼¥¸¥ç¥ó¤ÇƱÍͤËÆ°ºî¤·¤Þ¤¹¡£va_arg() ¤Ï ap ¤ÎÃͤòÊѹ¹¤¹¤ë¤¿¤á¡¢vfprintf() ¤Ø¤Î¸Æ¤Ó½Ð¤·¤ò¼¡¤Î¤è¤¦¤Ë¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£

(void)vfprintf(stderr, va_arg(ap, char *), ap);


¥Þ¥¯¥í FILENAME¡¢LINENUMBER¡¢¤ª¤è¤Ó WARNING ¤ÎÄêµÁ¤Ï¡¢¤ª¤½¤é¤¯¡¢errmsg() ¤ÎÀë¸À¤ÈƱ¤¸¥Ø¥Ã¥À¡¼¤Ë´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£

errmsg() ¤Ø¤Î¸Æ¤Ó½Ð¤·¤ÎÎã¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£

errmsg(FILENAME, "<command line>", "cannot open: %s\n",
argv[optind]);


³ÈÄ¥: Éä¹æ¤Ê¤·Êݸ¤ÈÃͤÎÊÝ»ý

C µ¬³Ê¤ÎÁð°Æ¤Î¡ÖRationale (ÏÀÍýŪº¬µò)¡×Àá¤Ë¡¢¼¡¤Î¤è¤¦¤Ê¾ðÊ󤬤¢¤ê¤Þ¤¹¡£
¡Ö¥á¥Ã¥»¡¼¥¸¤Ê¤·¤ÎÊѹ¹¡×¡£Éä¹æ¤Ê¤·Êݸ±é»»ÊÑ´¹¤Ë°Í¸¤¹¤ë¥×¥í¥°¥é¥à¤Ï¡¢¤ª¤½¤é¤¯¤Ï¥á¥Ã¥»¡¼¥¸¤òȯ¹Ô¤»¤º¤Ë¡¢°Û¤Ê¤ëÆ°ºî¤ò¹Ô¤¤¤Þ¤¹¡£¤³¤ì¤Ï¡¢¸½ºß¹­¤¯¹Ô¤ï¤ì¤Æ¤¤¤ë´·½¬¤ËÂФ·¤Æ°Ñ°÷²ñ¤¬¹Ô¤Ê¤Ã¤¿¤â¤Ã¤È¤â½ÅÂç¤ÊÊѹ¹¤Ç¤¢¤ë¤È¹Í¤¨¤é¤ì¤Þ¤¹¡£

"QUIET CHANGE ". A program that depends on unsigned preserving arithmetic conversions will behave differently, probably without complaint. This is considered to be the most serious change made by the Committee to a widespread current practice.

¤³¤ÎÀá¤Ç¤Ï¡¢¤³¤ÎÊѹ¹¤¬¥³¡¼¥Ç¥£¥ó¥°¤Ë¤É¤Î¤è¤¦¤Ë±Æ¶Á¤¹¤ë¤«¤òÀâÌÀ¤·¤Þ¤¹¡£

ÇØ·Ê

K&R ¤Î¡Ø¥×¥í¥°¥é¥ß¥ó¥°¸À¸ì C¡Ù¤Ë¤è¤ë¤È¡¢unsigned ¤Ï 1 ¤Ä¤À¤±¤Î·¿¤ò»ØÄꤷ¤Æ¤¤¤Þ¤·¤¿¡£¤Ä¤Þ¤ê¡¢unsigned char¡¢unsigned short¡¢unsigned long ¤Ï¤¢¤ê¤Þ¤»¤ó¤Ç¤·¤¿¡£¤·¤«¤·¡¢¤Û¤È¤ó¤É¤Î C ¥³¥ó¥Ñ¥¤¥é¤Ë¤Ï¤¹¤°¤Ë¤³¤ì¤é¤Î·¿¤¬Äɲ䵤ì¤Þ¤·¤¿¡£unsigned long ¤ò¼ÂÁõ¤»¤º¡¢»Ä¤ê¤Î 2 ¤Ä¤À¤±¤ò¼ÂÁõ¤¹¤ë¥³¥ó¥Ñ¥¤¥é¤â¤¢¤ê¤Þ¤¹¡£ÅöÁ³¡¢¼°¤ÎÃæ¤Ç¤³¤ì¤é¤Î¿·¤·¤¤·¿¤¬Â¾¤Î·¿¤ÈÊ»ÍѤµ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¼ÂÁõ¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë·¿³ÈÄ¥µ¬Â§¤¬Å¬ÍѤµ¤ì¤Þ¤·¤¿¡£

¤Û¤È¤ó¤É¤Î C ¥³¥ó¥Ñ¥¤¥é¤Ç¤Ï¡¢¤è¤ê´Êñ¤Êµ¬Â§¡ÖÉä¹æ¤Ê¤·Êݸ¡×¤¬»ÈÍѤµ¤ì¤Æ¤¤¤Þ¤¹¡£¤Ä¤Þ¤ê¡¢unsigned ·¿¤ò³ÈÄ¥¤¹¤ëɬÍפ¬¤¢¤ë¤È¤­¤Ï unsigned ·¿¤Ë³ÈÄ¥¤·¤Þ¤¹¡£¤½¤·¤Æ¡¢unsigned ·¿¤¬ signed ·¿¤Èº®¹ç¤µ¤ì¤Æ¤¤¤ë¤È¤­¤â¡¢unsigned ·¿¤Ë³ÈÄ¥¤µ¤ì¤Þ¤¹¡£

ANSI/ISO C ¤Ç¤Ï¡¢¡ÖÃͤÎÊÝ»ý¡×¤È¤¤¤¦µ¬Â§¤â»ØÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£¤³¤Îµ¬Â§¤Ç¤Ï¡¢³ÈÄ¥·ë²Ì¤Î·¿¤Ï¡¢¥ª¥Ú¥é¥ó¥É¤Î·¿¤ÎÁêÂÐŪ¤Ê¥µ¥¤¥º¤Ë¤è¤Ã¤Æ°Û¤Ê¤ê¤Þ¤¹¡£unsigned char ¤Þ¤¿¤Ï unsigned short ¤ò³ÈÄ¥¤¹¤ë¤È¤­¡¢int ¤¬¤è¤ê¾®¤µ¤¤·¿¤ÎÃͤò¤¹¤Ù¤Æɽ¸½¤Ç¤­¤ëÂ礭¤µ¤Ç¤¢¤ë¾ì¹ç¤Ï¡¢³ÈÄ¥·ë²Ì¤Î·¿¤Ï int ¤Ë¤Ê¤ê¤Þ¤¹¡£¤½¤ì°Ê³°¤Î¾ì¹ç¡¢unsigned int ¤Ë¤Ê¤ê¤Þ¤¹¡£¤³¤Î¡ÖÃͤÎÊÝ»ý¡×µ¬Â§¤Ë½¾¤¨¤Ð¡¢¤Û¤È¤ó¤É¤Î¼°¤¬ÌµÆñ¤Ê±é»»·ë²Ì¤Ë¤Ê¤ê¤Þ¤¹¡£

¥³¥ó¥Ñ¥¤¥ë¤ÎÆ°ºî

ANSI/ISO C ¥³¥ó¥Ñ¥¤¥é¤Ï¡¢°Ü¹Ô¥â¡¼¥É (-Xt) ¤Þ¤¿¤Ï ANSI/ISO °ÊÁ°¤Î¥â¡¼¥É (-Xs) ¤Ç¤Ï¡¢Éä¹æ¤Ê¤·Êݸ³ÈÄ¥µ¬Â§¤òŬÍѤ·¤Þ¤¹¡£½àµò¥â¡¼¥É (-Xc) ¤ª¤è¤Ó ANSI/ISO ¥â¡¼¥É (-Xa) ¤Ç¤Ï¡¢ÃÍÊÝ»ý³ÈÄ¥µ¬Â§¤ò»ÈÍѤ·¤Þ¤¹¡£

Îã 1: ¥­¥ã¥¹¥È¤Î»ÈÍÑ

¼¡¤Î¥³¡¼¥É¤Ç¤Ï¡¢unsigned char ¤¬ int ¤è¤ê¾®¤µ¤¤¤È²¾Äꤷ¤Þ¤¹¡£

int f(void)
{
    int i = -2;
    unsigned char uc = 1;

 
   return (i + uc) < 17;
}


¾åµ­¥³¡¼¥É¤ò»ÈÍѤ¹¤ë¤È¡¢-xtransition ¥ª¥×¥·¥ç¥ó¤ò»ÈÍѤ·¤¿¤È¤­¤Ë¡¢¼¡¤Î·Ù¹ð¤¬È¯¹Ô¤µ¤ì¤Þ¤¹¡£

 6 ¹ÔÌÜ: ·Ù¹ð: ANSI/ISO C ¤Ç¤Ï "<" ¤Î°ÕÌ£¤¬ÊѤï¤ê¤Þ¤¹¡£ÌÀ¼¨Åª¤Ê¥­¥ã¥¹¥È
¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£

²Ã»»¤Î·ë²Ì¤Î·¿¤Ï int (ÃÍÊÝ»ý) ¤Þ¤¿¤Ï unsigned int (Éä¹æ¤Ê¤·Êݸ) ¤Ç¤¹¡£¤·¤«¤·¡¢¤É¤Á¤é¤Î¾ì¹ç¤Ç¤â¥Ó¥Ã¥È¥Ñ¥¿¡¼¥ó¤ÏƱ¤¸¤Ç¤¹¡£2 ¤ÎÊä¿ô¤ò»ÈÍѤ¹¤ë¥Þ¥·¥ó¤Ç¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£

    i:  111...110 (-2)
+   uc: 000...001 ( 1)
===================
        111...111 (-1 or UINT_MAX)


¤³¤Î¥Ó¥Ã¥Èɽ¸½¤Ï¡¢int ¤Ç¤Ï -1 ¤ËÂбþ¤·¡¢unsigned int ¤Ç¤Ï UINT_MAX ¤ËÂбþ¤·¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢·ë²Ì¤Î·¿¤¬ int ¤Î¾ì¹ç¡¢Éä¹æÉÕ¤­Èæ³Ó¤¬»ÈÍѤµ¤ì¡¢¡Ö¤è¤ê¾®¤µ¤¤¤«¡×¤ÎÅú¤¨¤Ï¿¿¤Ë¤Ê¤ê¤Þ¤¹¡£·ë²Ì¤Î·¿¤¬ unsigned int ¤Î¾ì¹ç¡¢Éä¹æ¤Ê¤·¤ÎÈæ³Ó¤¬¹Ô¤ï¤ì¡¢¡Ö¤è¤ê¾®¤µ¤¤¤«¡×¤ÎÅú¤¨¤Ïµ¶¤Ë¤Ê¤ê¤Þ¤¹¡£

¥­¥ã¥¹¥È¤Î²Ã»»¤ò»ÈÍѤ¹¤ë¤È¡¢2 ¤Ä¤ÎÆ°ºî¤Î¤¦¤Á¡¢¤É¤Á¤é¤ò´õ˾¤¹¤ë¤«¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£

value preserving: 
    (i + (int)uc) < 17 
unsigned preserving:
    (i + (unsigned int)uc) < 17


¥³¥ó¥Ñ¥¤¥é¤¬°Û¤Ê¤ì¤ÐƱ¤¸¥³¡¼¥É¤ËÂФ¹¤ë²ò¼á¤â°Û¤Ê¤ë¤¿¤á¡¢¤³¤Î¼°¤ÏÛ£Ëæ¤Ë¤Ê¤ë²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£¥­¥ã¥¹¥È¤Î²Ã»»¤ò»ÈÍѤ¹¤ë¤³¤È¤Ë¤è¤ê¡¢¥³¡¼¥É¤¬Æɤߤ䤹¤¯¤Ê¤ë¤ÈƱ»þ¤Ë¡¢·Ù¹ð¥á¥Ã¥»¡¼¥¸¤âȯ¹Ô¤µ¤ì¤Ê¤¯¤Ê¤ê¤Þ¤¹¡£

¥Ó¥Ã¥È¥Õ¥£¡¼¥ë¥É

Ʊ¤¸Æ°ºî¤¬¡¢¥Ó¥Ã¥È¥Õ¥£¡¼¥ë¥ÉÃͤγÈÄ¥¤Ë¤âŬÍѤµ¤ì¤Þ¤¹¡£ANSI/ISO C ¤Ç¤Ï¡¢int ¤Þ¤¿¤Ï unsigned int ¥Ó¥Ã¥È¥Õ¥£¡¼¥ë¥ÉÆâ¤Î¥Ó¥Ã¥È¤Î¿ô¤¬ int Ãæ¤Î¥Ó¥Ã¥È¤Î¿ô¤è¤ê¤â¾¯¤Ê¤¤¾ì¹ç¡¢³ÈÄ¥¤µ¤ì¤ë·¿¤Ï int ¤Ç¤¹¡£¤½¤ì°Ê³°¤Î¾ì¹ç¡¢³ÈÄ¥¤µ¤ì¤ë·¿¤Ï unsigned int ¤Ç¤¹¡£¤Û¤È¤ó¤É¤Î¸Å¤¤ C ¥³¥ó¥Ñ¥¤¥é¤Ç¤Ï¡¢ÌÀ¼¨Åª¤ÊÉä¹æ¤Ê¤·¥Ó¥Ã¥È¥Õ¥£¡¼¥ë¥É¤Î¾ì¹ç¡¢³ÈÄ¥¤µ¤ì¤ë·¿¤Ï unsigned int ¤Ç¤¹¡£¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï int ¤Ç¤¹¡£

¤³¤Î¾ì¹ç¤â¡¢¥­¥ã¥¹¥È¤ò»ÈÍѤ¹¤ë¤³¤È¤Ë¤è¤ê¡¢Û£Ëæ¤Ë¤Ê¤ë¤³¤È¤òËɤ°¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

Îã 2: Ʊ¤¸·ë²Ì

¼¡¤Î¥³¡¼¥É¤Ç¤Ï¡¢unsigned short ¤È unsigned char ¤ÎξÊý¤¬ int ¤è¤ê¤â¶¹¤¤¤È²¾Äꤷ¤Þ¤¹¡£

int f(void) 
{ 
    unsigned short us;
    unsigned char uc;
    return uc < us;
}


¤³¤ÎÎã¤Ç¤Ï¡¢2 ¤Ä¤Î¼«Æ°ÊÑ¿ô¤Ï int ¤Þ¤¿¤Ï unsigned int ¤Î¤É¤Á¤é¤«¤Ë³ÈÄ¥¤µ¤ì¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢Èæ³ÓÂоݤÏÉä¹æ¤Ê¤·¤Ë¤Ê¤ë¤³¤È¤â¡¢Éä¹æÉÕ¤­¤Ë¤Ê¤ë¤³¤È¤â¤¢¤ê¤Þ¤¹¡£¤·¤«¤·¡¢¤É¤Á¤é¤òÁª¤ó¤Ç¤â·ë²Ì¤ÏƱ¤¸¤Ê¤Î¤Ç¡¢·Ù¹ð¤Ïȯ¹Ô¤µ¤ì¤Þ¤»¤ó¡£

À°¿ôÄê¿ô

¼°¤ÈƱÍͤˡ¢¤¢¤ëÀ°¿ôÄê¿ô¤Î·¿¤Îµ¬Â§¤âÊѹ¹¤µ¤ì¤Þ¤·¤¿¡£K&R C ¤Ç¤Ï¡¢ÀÜÈø¼­¤Ê¤·¤Î 10 ¿ÊÄê¿ô¤Î·¿¤Ï¡¢¤½¤ÎÃͤ¬ int ¤Ë¼ý¤Þ¤ë¾ì¹ç¤À¤± int ¤Ç¤·¤¿¡£ÀÜÈø¼­¤Ê¤·¤Î 8 ¿ÊÄê¿ô¤Þ¤¿¤Ï 16 ¿ÊÄê¿ô¤Î·¿¤Ï¡¢¤½¤ÎÃͤ¬ unsigned int ¤Ë¼ý¤Þ¤ë¾ì¹ç¤À¤± int ¤Ç¤·¤¿¡£¤½¤ì°Ê³°¤Î¾ì¹ç¡¢À°¿ôÄê¿ô¤Î·¿¤Ï long ¤Ç¤·¤¿¡£¤·¤¿¤¬¤Ã¤Æ¡¢Ãͤ¬·ë²Ì¤Î·¿¤Ë¼ý¤Þ¤é¤Ê¤¤¤³¤È¤¬¤¢¤ê¤Þ¤·¤¿¡£ANSI/ISO C ¤Ç¤Ï¡¢Äê¿ô¤Î·¿¤Ï¡¢¼¡¤Î¥ê¥¹¥È¤Î¤¦¤Á¡¢Ãͤò³ÊǼ¤Ç¤­¤ëºÇ½é¤Î·¿¤È¤Ê¤ê¤Þ¤¹¡£

ÀÜÈø¼­¤Ê¤· 10 ¿Ê¿ô:

int¡¢long¡¢unsigned long

ÀÜÈø¼­¤Ê¤· 8 ¿Ê¿ô¤Þ¤¿¤Ï 16 ¿Ê¿ô:

int¡¢unsigned int¡¢long¡¢unsigned long

ÀÜÈø¼­ U ÉÕ¤­:

unsigned int¡¢unsigned long

ÀÜÈø¼­ L ÉÕ¤­:

long¡¢unsigned long

ÀÜÈø¼­ UL ÉÕ¤­:

unsigned long

ANSI/ISO C ¥³¥ó¥Ñ¥¤¥é¤Ç -xtransition ¥ª¥×¥·¥ç¥ó¤ò»ÈÍѤ¹¤ë¤È¤­¡¢Äê¿ô¤Î·¿µ¬Â§¤Ë¤è¤Ã¤Æ¼°¤ÎÆ°ºî¤¬°Û¤Ê¤ë¾ì¹ç¤Ï·Ù¹ð¤¬È¯¹Ô¤µ¤ì¤Þ¤¹¡£¸Å¤¤À°¿ôÄê¿ô¤Î·¿µ¬Â§¤Ï¡¢°Ü¹Ô¥â¡¼¥É (-Xt) ¤À¤±¤ÇŬÍѤµ¤ì¤Þ¤¹¡£ANSI/ISO ¥â¡¼¥É (-Xa) ¤È½àµò¥â¡¼¥É (-Xc) ¤Ç¤Ï¡¢¿·¤·¤¤µ¬Â§¤¬Å¬ÍѤµ¤ì¤Þ¤¹¡£

Îã 3: À°¿ôÄê¿ô

¼¡¤Î¥³¡¼¥É¤Ç¤Ï¡¢int ¤¬ 16 ¥Ó¥Ã¥È¤Ç¤¢¤ë¤È²¾Äꤷ¤Þ¤¹¡£

int f(void)
{
    int i = 0;

 
    return i > 0xffff;
}


16 ¿ÊÄê¿ô¤Î·¿¤Ï int (2 ¤ÎÊä¿ô¤ò»ÈÍѤ¹¤ë¥Þ¥·¥ó¾å¤Ç -1 ¤ÎÃͤò»ý¤Ä) ¤Þ¤¿¤Ï unsigned int (65535 ¤ÎÃͤò»ý¤Ä) ¤Î¤É¤Á¤é¤«¤Ç¤¹¡£Èæ³Ó·ë²Ì¤Ï¡¢ANSI °ÊÁ°¥â¡¼¥É (-Xs) ¤È°Ü¹Ô¥â¡¼¥É (-Xt) ¤Ç¤Ï¿¿¤Ç¡¢ANSI ¥â¡¼¥É (-Xa) ¤È½àµò¥â¡¼¥É (-Xc) ¤Ç¤Ïµ¶¤Ç¤¹¡£

¤³¤Î¾ì¹ç¤â¡¢¥­¥ã¥¹¥È¤òŬÀڤ˻ÈÍѤ¹¤ë¤³¤È¤Ë¤è¤ê¡¢¥³¡¼¥É¤¬Æɤߤ䤹¤¯¤Ê¤ê¡¢·Ù¹ð¤âȯ¹Ô¤µ¤ì¤Ê¤¯¤Ê¤ê¤Þ¤¹¡£

-Xt, -Xs modes:
i > (int)0xffff

-Xa, -Xc modes:
i > (unsigned int)0xffff
or
i > 0xffffU


ÀÜÈø¼­ U ʸ»ú¤Ï ANSI/ISO C ¤Î¿·¤·¤¤µ¡Ç½¤Ç¤¢¤ë¤¿¤á¡¢¸Å¤¤¥³¥ó¥Ñ¥¤¥é¤Ç¤Ï¤ª¤½¤é¤¯¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤¬À¸À®¤µ¤ì¤Þ¤¹¡£

¥È¡¼¥¯¥ó²½¤ÈÁ°½èÍý

°ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤Î C ¤Ç¤â¤Ã¤È¤âÉÔÌÀ³Î¤Ê»ÅÍͤϡ¢³Æ¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤òʸ»ú¤Î½¸¹ç¤«¤é°ìÏ¢¤Î¥È¡¼¥¯¥ó¤ËÊÑ´¹¤·¤Æ¹½Ê¸²òÀϤǤ­¤ë¤è¤¦¤Ë¤¹¤ë¤Þ¤Ç¤ÎÁàºî¤Ç¤·¤ç¤¦¡£¶ñÂÎŪ¤Ë¤Ï¡¢¶õÇò (¥³¥á¥ó¥È¤â´Þ¤à) ¤Îǧ¼±¡¢Ï¢Â³¤·¤¿Ê¸»ú¤Î¥È¡¼¥¯¥ó²½¡¢Á°½èÍý»ØÎá¹Ô¤Î½èÍý¡¢¤ª¤è¤Ó¥Þ¥¯¥í¤ÎÃÖ´¹¤Ê¤É¤¬¤¢¤ê¤Þ¤¹¡£¤·¤«¤·¡¢¤³¤ì¤éÁàºî¤ÎÍ¥Àè½ç°Ì¤ÏÊݾڤµ¤ì¤Æ¤¤¤Þ¤»¤ó¤Ç¤·¤¿¡£

ANSI/ISO C ¤ÎËÝÌõÃʳ¬

ANSI/ISO C ¤Ç¤Ï¡¢¤³¤Î¤è¤¦¤ÊËÝÌõÃʳ¬¤Î½çÈÖ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£

  1. ¥½¡¼¥¹¥Õ¥¡¥¤¥ëÆâ¤Î¤¹¤Ù¤Æ¤Î 3 ʸ»úɽµ­¥·¡¼¥±¥ó¥¹¤¬ÃÖ´¹¤µ¤ì¤Þ¤¹¡£ANSI/ISO C ¤Ï¡¢9 ¤Ä¤Î 3 ʸ»úɽµ­¥·¡¼¥±¥ó¥¹¤ò»ý¤Ã¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤é¤Î¥·¡¼¥±¥ó¥¹¤Ï¤â¤È¤â¤Èʸ»ú¥»¥Ã¥È¤ÎÉÔ´°Á´¤ÊÅÀ¤òÊ䤦¤¿¤á¤ËƳÆþ¤µ¤ì¤Þ¤·¤¿¡£¤·¤«¤·¡¢¸½ºß¤Ç¤Ï¡¢¤³¤Î 3 ʸ»ú¥·¡¼¥±¥ó¥¹¤Ï ISO 646-1983 ʸ»ú¥»¥Ã¥È¤Ë´Þ¤Þ¤ì¤Ê¤¤Ê¸»ú¤ò»ØÄꤹ¤ë¤¿¤á¤Ë»ÈÍѤµ¤ì¤Æ¤¤¤Þ¤¹¡£

    ɽ 7-1   3 ʸ»ú¥·¡¼¥±¥ó¥¹
    3 ʸ»ú¥·¡¼¥±¥ó¥¹ ÊÑ´¹¸å¤Îʸ»ú 3 ʸ»ú¥·¡¼¥±¥ó¥¹ ÊÑ´¹¸å¤Îʸ»ú
    ??=
    #
    ??<
    {
    ??-
    ~
    ??>
    }
    ??(
    [
    ??/
    \
    ??)
    ]
    ??'
    ^
    ??!
    |



ANSI/ISO C ¥³¥ó¥Ñ¥¤¥é¤Ï¾åµ­¥·¡¼¥±¥ó¥¹¤òÍý²ò¤¹¤ë¤Ï¤º¤Ç¤¹¡£¤·¤«¤·¡¢¤³¤ì¤é¤Î¥·¡¼¥±¥ó¥¹¤ò»ÈÍѤ¹¤ë¤³¤È¤Ï¤ª´«¤á¤·¤Þ¤»¤ó¡£-xtransition ¥ª¥×¥·¥ç¥ó¤ò»ÈÍѤ·¤¿¤È¤­¡¢°Ü¹Ô¥â¡¼¥É (-Xt) ¤Ç¤Ï¡¢ANSI/ISO C ¥³¥ó¥Ñ¥¤¥é¤Ï 3 ʸ»ú¥·¡¼¥±¥ó¥¹¤òÃÖ´¹¤¹¤ë¤¿¤Ó¤Ë·Ù¹ð¤òȯ¹Ô¤·¤Þ¤¹ (¥³¥á¥ó¥ÈÆâ¤Ç¤â)¡£¤¿¤È¤¨¤Ð¡¢¼¡¤ÎÎã¤ò¹Í¤¨¤Æ¤¯¤À¤µ¤¤¡£

/* ¥³¥á¥ó¥È *??/
/* ¥³¥á¥ó¥È¤Î³¤­? */


??/ ¤Ï¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤Ë¤Ê¤ê¤Þ¤¹¡£¤³¤Îʸ»ú¤È¤½¤ì¤Ë³¤¯²þ¹Ô¤Ïºï½ü¤µ¤ì¤Þ¤¹¡£·ë²Ì¤È¤·¤Æ¡¢¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£

/* ¥³¥á¥ó¥È */* ¥³¥á¥ó¥È¤Î³¤­? */


2 ¹ÔÌܤκǽé¤Î / ¤Ï¡¢¥³¥á¥ó¥È¤Î½ª¤ï¤ê¤Ç¤¹¡£¼¡¤Î¥È¡¼¥¯¥ó¤Ï * ¤Ç¤¹¡£

  1. ¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤È²þ¹Ôʸ»ú¤ÎÁȤ߹ç¤ï¤»¤¬¤¹¤Ù¤Æºï½ü¤µ¤ì¤Þ¤¹¡£

  2. ¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤¬Á°½èÍý¥È¡¼¥¯¥ó¤È¶õÇòʸ»ú¤Î¥·¡¼¥±¥ó¥¹¤ËÊÑ´¹¤µ¤ì¤Þ¤¹¡£³Æ¥³¥á¥ó¥È¤ÏɬÍ׺ÇÄã¸Â¤Î¶õÇòʸ»ú¤ÇÃÖ´¹¤µ¤ì¤Þ¤¹¡£

  3. ¤¹¤Ù¤Æ¤ÎÁ°½èÍý»ØÎ᤬½èÍý¤µ¤ì¡¢¤¹¤Ù¤Æ¤Î¥Þ¥¯¥í¸Æ¤Ó½Ð¤·¤¬ÃÖ´¹¤µ¤ì¤Þ¤¹¡£#include ¤Ç¥¤¥ó¥¯¥ë¡¼¥É¤µ¤ì¤¿³Æ¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤Ï¡¢ÆâÍƤ¬»ØÎá¹Ô¤ËÃÖ´¹¤µ¤ì¤ëÁ°¤Î½é´üÃʳ¬¤Ç¼Â¹Ô¤µ¤ì¤Þ¤¹¡£

  4. ¤¹¤Ù¤Æ¤Î¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹ (ʸ»úÄê¿ô¤Èʸ»úÎó¥ê¥Æ¥é¥ë) ¤¬²ò¼á¤µ¤ì¤Þ¤¹¡£

  5. ÎÙÀܤ¹¤ëʸ»úÎó¥ê¥Æ¥é¥ë¤¬Ï¢·ë¤µ¤ì¤Þ¤¹¡£

  6. ¤¹¤Ù¤Æ¤ÎÁ°½èÍý¥È¡¼¥¯¥ó¤¬Ä̾ï¤Î¥È¡¼¥¯¥ó¤ËÊÑ´¹¤µ¤ì¤Þ¤¹¡£¥³¥ó¥Ñ¥¤¥é¤Ï¤³¤ì¤é¤Î¥È¡¼¥¯¥ó¤òŬÀڤ˹½Ê¸²òÀϤ·¤Æ¡¢¥³¡¼¥É¤òÀ¸À®¤·¤Þ¤¹¡£

  7. ¤¹¤Ù¤Æ¤Î³°Éô¥ª¥Ö¥¸¥§¥¯¥È¤È´Ø¿ô»²¾È¤¬²ò¼á½èÍý¤µ¤ì¡¢ºÇ½ªÅª¤Ê¥×¥í¥°¥é¥à¤Ë¤Ê¤ê¤Þ¤¹¡£

¸Å¤¤ C ¤ÎËÝÌõÃʳ¬

°ÊÁ°¤Î C ¥³¥ó¥Ñ¥¤¥é¤Ï¡¢¤³¤Î¤è¤¦¤Êñ½ã¤Ê½çÈ֤˽¾¤¤¤Þ¤»¤ó¤Ç¤·¤¿¡£¤Þ¤¿¡¢¤³¤ì¤é¤ÎÃʳ¬¤¬¤¤¤ÄŬÍѤµ¤ì¤ë¤«¤âÊݾڤµ¤ì¤Æ¤¤¤Þ¤»¤ó¤Ç¤·¤¿¡£¥³¥ó¥Ñ¥¤¥é¤È¤ÏÊ̤Υץê¥×¥í¥»¥Ã¥µ¤¬¡¢¥Þ¥¯¥í¤òÃÖ´¹¤·¤Æ»ØÎá¹Ô¤ò½èÍý¤¹¤ë¤È¤­¤Ë¡¢¥È¡¼¥¯¥ó¤È¶õÇò¤òǧ¼±¤·¤Æ¤¤¤Þ¤·¤¿¡£¤½¤·¤Æ¡¢¥³¥ó¥Ñ¥¤¥é¤¬¥×¥ê¥×¥í¥»¥Ã¥µ¤Î½ÐÎϤòŬÀڤ˺ƥȡ¼¥¯¥ó²½¤·¡¢¸À¸ì¤ò¹½Ê¸²òÀϤ·¡¢¥³¡¼¥É¤òÀ¸À®¤·¤Æ¤¤¤Þ¤·¤¿¡£

¥×¥ê¥×¥í¥»¥Ã¥µÆâ¤Î¥È¡¼¥¯¥ó²½½èÍý¤ÏɬÍפ˱þ¤¸¤Æ¹Ô¤ï¤ì¤ëÁàºî¤Ç¡¢¥Þ¥¯¥íÃÖ´¹¤Ï (¥È¡¼¥¯¥ó¥Ù¡¼¥¹¤Ç¤Ï¤Ê¤¯) ʸ»ú¥Ù¡¼¥¹¤ÎÁàºî¤È¤·¤Æ¹Ô¤ï¤ì¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢Á°½èÍýÃæ¤Ë¥È¡¼¥¯¥ó¤È¶õÇò¤ÏÂ礭¤¯ÊÑÆ°¤¹¤ë²ÄǽÀ­¤¬¤¢¤ê¤Þ¤·¤¿¡£

2 ¤Ä¤ÎÊýË¡¤Î´Ö¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«°Û¤Ê¤ëÅÀ¤¬¤¢¤ê¤Þ¤¹¡£¤³¤ÎÀá¤Î¸åȾ¤Ç¤Ï¡¢¥Þ¥¯¥íÃÖ´¹Ãæ¤ËȯÀ¸¤¹¤ë¹Ô¤ÎÏ¢·ë¡¢¥Þ¥¯¥íÃÖ´¹¡¢Ê¸»úÎ󲽡¢¤ª¤è¤Ó¥È¡¼¥¯¥ó¤ÎÏ¢·ë¤Ë¤è¤Ã¤Æ¡¢¥³¡¼¥É¤ÎÆ°ºî¤¬¤É¤Î¤è¤¦¤ËÊѲ½¤¹¤ë¤«¤òÀâÌÀ¤·¤Þ¤¹¡£

ÏÀÍýŪ¤Ê¥½¡¼¥¹¹Ô

K&R C ¤Ç¤Ï¡¢¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤È²þ¹Ô¤òÁȤ߹ç¤ï¤»¤Î¼¡¤Î¹Ô¤Ë¤Ï¡¢»ØÎᡢʸ»úÎó¥ê¥Æ¥é¥ë¡¢Ê¸»úÄê¿ô¤·¤«»ØÄê¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£ANSI/ISO C ¤Ç¤Ï¤³¤Î³µÇ°¤¬³ÈÄ¥¤µ¤ì¡¢¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤È²þ¹Ô¤ÎÁȤߤμ¡¤Î¹Ô¤Ë¡¢¤¢¤é¤æ¤ë¤â¤Î¤ò»ØÄê¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤·¤¿¡£K&R ¤Ç¤Ï 1 ¹Ô¤Ï 1 ¹Ô¤Ç¤·¤¿¤¬ ANSIC ¤Ç¤ÏÊ£¿ô¹ÔÁȤ߹ç¤ï¤»¤Æ 1 ¹Ô¤È¤Ç¤­¡¢¤³¤ì¤¬ÏÀÍý¹Ô¤Ç¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤È²þ¹Ô¤ÎÁȤ߹ç¤ï¤»¤Î¤É¤Á¤é¦¤Ë¤¢¤ë¤«¤Ë¤è¤Ã¤Æ¥È¡¼¥¯¥ó¤Îǧ¼±¤¬°Û¤Ê¤ë¥³¡¼¥É¤Ï¡¢´üÂԤɤª¤ê¤ËÆ°ºî¤·¤Þ¤»¤ó¡£

¥Þ¥¯¥íÃÖ´¹

ANSI/ISO C °ÊÁ°¤Ë¤Ï¡¢¥Þ¥¯¥íÃÖ´¹½èÍý¤Ë¤Ä¤¤¤Æ¤Ï¾ÜºÙ¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£¤³¤ÎÛ£Ë椵¤Î¤¿¤á¤Ë¡¢½èÍý·Ï¤Ë¿¤¯¤Îº¹¤¬À¸¤Þ¤ì¤Þ¤·¤¿¡£¤·¤¿¤¬¤Ã¤Æ¡¢ÌÀÇò¤ÊÄê¿ôÃÖ´¹¤ä´Êñ¤Ê´Ø¿ô¤Î¤è¤¦¤Ê¥Þ¥¯¥í¤è¤ê¤âÊ£»¨¤Ê¤â¤Î¤ò»ý¤Ä¥³¡¼¥É¤Ï¡¢¤ª¤½¤é¤¯´°Á´¤Ë¤Ï°Ü¿¢¤Ç¤­¤Þ¤»¤ó¡£¤³¤Î¥Þ¥Ë¥å¥¢¥ë¤Ç¤Ï¡¢¸Å¤¤ C ¤È ANSI/ISO C ´Ö¤Î¥Þ¥¯¥íÃÖ´¹¼ÂÁõ¤Î°ã¤¤¤ò¤¹¤Ù¤ÆÀâÌÀ¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£¤Û¤È¤ó¤É¤¹¤Ù¤Æ¤Î¥Þ¥¯¥íÃÖ´¹¤Î·ë²Ì¤Ï¡¢Á°¤È¤Þ¤Ã¤¿¤¯Æ±¤¸¥È¡¼¥¯¥ó¤ÎϢ³¤Ë¤Ê¤ê¤Þ¤¹¡£¤¿¤À¤·¡¢ANSI/ISO C ¥Þ¥¯¥íÃÖ´¹¥¢¥ë¥´¥ê¥º¥à¤Ï¡¢¸Å¤¤ C ¤Ç¤Ï¤Ç¤­¤Ê¤«¤Ã¤¿¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¼¡¤ÎÎã¤ò¸«¤Æ¤¯¤À¤µ¤¤¡£

#define name (*name)


¤³¤ÎÎã¤Ï¡¢¤¹¤Ù¤Æ¤Î name ¤ò name ·Ðͳ¤Î´ÖÀÜ»²¾È¤ÇÃÖ´¹¤·¤Þ¤¹¡£¸Å¤¤ C ¥×¥ê¥×¥í¥»¥Ã¥µ¤Ï¿ô¿¤¯¤Î³ç¸Ì¤È¥¢¥¹¥¿¥ê¥¹¥¯¤òÀ¸À®¤·¡¢¤È¤­¤Ë¤Ï¡¢¥Þ¥¯¥í¤ÎºÆµ¢¤Ë¤Ä¤¤¤Æ¥¨¥é¡¼¤òÀ¸À®¤¹¤ë¾ì¹ç¤â¤¢¤ê¤Þ¤¹¡£

ANSI/ISO C ¤Ë¤è¤ë¥Þ¥¯¥íÃÖ´¹ÊýË¡¤Î¼ç¤ÊÊѹ¹¤Ï¡¢¥Þ¥¯¥íÃÖ´¹±é»»»Ò # ¤È ## ¤Î¥ª¥Ú¥é¥ó¥É°Ê³°¤Î¥Þ¥¯¥í°ú¿ô¤¬Í×µá¤Ç¤¢¤ë¤³¤È¡¢ÃÖ´¹¥È¡¼¥¯¥ó¥ê¥¹¥È¤Ç¤ÎÃÖ´¹Á°¤ËºÆµ¢Åª¤ËŸ³«¤¹¤ë¤³¤È¤Ç¤¹¡£¤¿¤À¤·¡¢¤³¤ÎÊѹ¹¤Ë¤è¤Ã¤Æ¡¢¼ÂºÝ¤ËÀ¸À®¤µ¤ì¤ë¥È¡¼¥¯¥ó¤Ëº¹¤¬À¸¤¸¤ë¤³¤È¤ÏÌÇ¿¤Ë¤¢¤ê¤Þ¤»¤ó¡£

ʸ»úÎó¤Î»ÈÍÑ


Ãí - ANSI/ISO C ¤Ç¤Ï¡¢-xtransition ¥ª¥×¥·¥ç¥ó¤ò»ÈÍѤ¹¤ë¤È¤­¡¢¼¡¤ÎÎã ( °õ) ¤ò»ÈÍѤ¹¤ë¤È¡¢¸Å¤¤µ¡Ç½¤ò»ÈÍѤ·¤Æ¤¤¤ë¤È¤¤¤¦·Ù¹ð¤¬À¸À®¤µ¤ì¤Þ¤¹¡£°Ü¹Ô¥â¡¼¥É (-Xt ¤È -Xs) ¤Î¾ì¹ç¤Î¤ß¡¢·ë²Ì¤Ï°ÊÁ°¤Î¥Ð¡¼¥¸¥ç¥ó¤Î C ¤ÈƱ¤¸¤Ë¤Ê¤ê¤Þ¤¹¡£

K&R C ¤Ç¤Ï¡¢¼¡¤Î¥³¡¼¥É¤Ïʸ»úÎó¥ê¥Æ¥é¥ë¡Öx y!¡×¤òÀ¸À®¤·¤Þ¤·¤¿¡£

#define str(a) "a!"							 
str(x y) 


¤·¤¿¤¬¤Ã¤Æ¡¢¥×¥ê¥×¥í¥»¥Ã¥µ¤Ï¡¢Ê¸»úÎó¥ê¥Æ¥é¥ë¤Èʸ»úÄê¿ô¤ÎÆâÉô¤Ç¡¢¥Þ¥¯¥í¥Ñ¥é¥á¡¼¥¿¤Î¤è¤¦¤Ë¸«¤¨¤ëʸ»ú¤ò¸¡º÷¤·¤Æ¤¤¤Þ¤·¤¿¡£ANSI/ISO C ¤Ï¤³¤Îµ¡Ç½¤Î½ÅÍ×À­¤òǧ¼±¤·¤Æ¤¤¤Þ¤·¤¿¤¬¡¢¥È¡¼¥¯¥ó¤ÎÉôʬ¤Ë¤³¤ÎÁàºî¤ò¹Ô¤¦¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£ANSI/ISO C ¤Ç¤Ï¡¢¾åµ­¥Þ¥¯¥í¤Ïʸ»úÎó¥ê¥Æ¥é¥ë¡Öa!¡×¤òÀ¸À®¤·¤Þ¤¹¡£ANSI/ISO C ¤Ç°ÊÁ°¤Î¸ú²Ì¤òÆÀ¤ë¤¿¤á¤Ë¤Ï¡¢# ¥Þ¥¯¥íÃÖ´¹±é»»»Ò¤Èʸ»úÎó¥ê¥Æ¥é¥ë¤ÎÏ¢·ë¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£

#define str(a) #a "!" 
str(x y) 


¾åµ­¥³¡¼¥É¤Ï¡¢2 ¤Ä¤Îʸ»úÎó¥ê¥Æ¥é¥ë¡Öx y¡×¤È¡Ö!¡×¤òÀ¸À®¤·¡¢Ï¢·ë¤·¤¿¸å¡¢Æ±¤¸
¡Öx y!¡×¤òÀ¸À®¤·¤Þ¤¹¡£

ʸ»úÄê¿ôÍѤÎÁàºî¤ò´°Á´¤ËÂåÍѤ¹¤ë¤â¤Î¤Ï¤¢¤ê¤Þ¤»¤ó¡£¤³¤Îµ¡Ç½¤Î¼ç¤Ê»ÈÍÑÊýË¡¤Ï¼¡¤Î¤è¤¦¤Ê¤â¤Î¤Ç¤·¤¿¡£

#define CNTL(ch) (037 & 'ch')										  
CNTL(L) 


¤³¤ì¤Ï¡¢¼¡¤òÀ¸À®¤·¤Þ¤¹¡£

(037 & 'L')


¤³¤ì¤Ï¡¢ASCII ¤Î Control-L ʸ»ú¤ÈƱ¤¸¤Ç¤¹¡£ºÇÎɤβò·èºö¤Ï¡¢¤³¤Î¥Þ¥¯¥í¤ò¼¡¤Î¤è¤¦¤ËÊѹ¹¤¹¤ë¤³¤È¤Ç¤¹¡£

#define CNTL(ch) (037 & (ch))
CNTL('L')


¤³¤Î¥³¡¼¥É¤ÎÊý¤¬Æɤߤ䤹¤¯¼°¤Ë¤âŬÍѤǤ­¤ë¤¿¤á¡¢¤è¤ê»È¤¤¤ä¤¹¤¯¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£

¥È¡¼¥¯¥ó¤ÎÏ¢·ë

K&R C ¤Ç¤Ï¡¢2 ¤Ä¤Î¥È¡¼¥¯¥ó¤òÏ¢·ë¤¹¤ë¤¿¤á¤Ë¡¢¾¯¤Ê¤¯¤È¤â 2 ¤Ä¤ÎÊýË¡¤¬¤¢¤ê¤Þ¤·¤¿¡£¼¡¤Î 2 ¤Ä¤Î¸Æ¤Ó½Ð¤·¤Ï¡¢2 ¤Ä¤Î¥È¡¼¥¯¥ó x ¤È l ¤«¤é 1 ¤Ä¤Î¼±ÊÌ»Ò xl ¤òÀ¸À®¤·¤Þ¤¹¡£

#define self(a) a
#define glue(a,b) a/**/b
self(x)1
glue(x,1)


ANSI/ISO C ¤Ç¤Ï¡¢¤É¤Á¤é¤ÎÊýË¡¤â»ÈÍѤǤ­¤Þ¤»¤ó¡£ANSI/ISO C ¤Ç¤Ï¡¢¾åµ­¤Î¸Æ¤Ó½Ð¤·¤Ï¡¢Î¾Êý¤È¤â 2 ¤Ä¤ÎÊÌ¡¹¤Î¥È¡¼¥¯¥ó x ¤È l ¤òÀ¸À®¤·¤Þ¤¹¡£¤·¤«¤·¡¢¾åµ­¤Î¸Æ¤Ó½Ð¤·¤ÎÆâ 2 ÈÖÌܤÎÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï¡¢## ¥Þ¥¯¥íÃÖ´¹±é»»»Ò¤ò»ÈÍѤ¹¤ì¤Ð¡¢ANSI/ISO C ÍѤ˽ñ¤­´¹¤¨¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

#define glue(a,b) a ## b
glue(x, 1)


# ¤È ## ¤Ï¡¢__STDC__ ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤È¤­¤À¤±¡¢¥Þ¥¯¥íÃÖ´¹±é»»»Ò¤È¤·¤Æ»ÈÍѤ·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£## ¤Ï¼ÂºÝ¤Î±é»»»Ò¤Î¤¿¤á¡¢ÄêµÁ¤È¸Æ¤Ó½Ð¤·¤ÎξÊý¤Ç¶õÇò¤ò¤è¤ê¼«Í³¤Ë»È¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¾åµ­¤Î¸Å¤¤·Á¼°¤ÎÏ¢·ëÊýË¡¤Î¤¦¤Á¡¢ºÇ½é¤ÎÊýË¡¤òľÀÜÂåÍѤǤ­¤ëÊýË¡¤Ï¤¢¤ê¤Þ¤»¤ó¡£
¤·¤«¤·¡¢¤³¤ÎÊýË¡¤Ç¤Ï¸Æ¤Ó½Ð¤·»þ¤ËÏ¢·ë¤Î½èÍý¤¬É¬Íפʤ¿¤á¡¢Â¾¤ÎÊýË¡¤ËÈæ¤Ù¤Æ¤¢¤Þ¤ê»ÈÍѤµ¤ì¤ë¤³¤È¤Ï¤¢¤ê¤Þ¤»¤ó¤Ç¤·¤¿¡£

const ¤È volatile

¥­¡¼¥ï¡¼¥É const ¤Ï C++ ¤Îµ¡Ç½¤Î 1 ¤Ä¤Ç¡¢ANSI/ISO C ¤Ë¼è¤êÆþ¤ì¤é¤ì¤Þ¤·¤¿¡£ANSI/ISO C °Ñ°÷²ñ¤¬Îà»÷¥­¡¼¥ï¡¼¥É volatile ¤òƳÆþ¤·¤¿¤È¤­¡¢¡Ö·¿½¤¾þ»Ò¡×¥«¥Æ¥´¥ê¤¬ºîÀ®¤µ¤ì¤Þ¤·¤¿¡£¤³¤Î¥«¥Æ¥´¥ê¤Ï¡¢¸½ºß¤Ç¤â¡¢ANSI/ISO C ¤Î¤¢¤¤¤Þ¤¤¤ÊÉôʬ¤È¤·¤Æ»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£

±¦ÊÕÃÍ (lvalue) ÀìÍѤη¿

const ¤È volatile ¤Ï¼±Ê̻Ҥη¿¤Î°ìÉô¤Ç¤¢¤ê¡¢µ­²±¥¯¥é¥¹¤Î°ìÉô¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£¤¿¤À¤·¡¢¤³¤ÎÉôʬ¤Ï¿¤¯¤Î¾ì¹ç¡¢¼°¤Îɾ²ÁÃæ¤Ë¥ª¥Ö¥¸¥§¥¯¥È¤ÎÃͤ¬¼è¤ê½Ð¤µ¤ì¤ë¤È¤­ (Àµ³Î¤Ë¤Ï¡¢±¦ÊÕÃͤ¬º¸ÊÕÃͤˤʤë¤È¤­) ¤Ë¡¢·¿¤Î°ìÈÖ¾å¤ÎÉôʬ¤«¤éºï½ü¤µ¤ì¤Þ¤¹¡£¤³¤ì¤é¤ÎÍѸì¤Ï¥×¥í¥È¥¿¥¤¥×ÂåÆþ¼°¡ÖL=R¡×¤«¤éÍè¤Æ¤¤¤Þ¤¹¡£¤³¤Î°ÕÌ£¤Ï¡¢º¸Â¦¤¬¥ª¥Ö¥¸¥§¥¯¥È (lvalue) ¤òľÀÜ»²¾È¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢±¦Â¦¤¬ÃÍ (rvalue) ¤Ç¤¢¤ë¤À¤±¤Ç¤è¤¤¤È¤¤¤¦¤³¤È¤Ç¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢lvalue ¤Ç¤¢¤ë¼°¤À¤±¤¬ const ¤Þ¤¿¤Ï volatile (¤¢¤ë¤¤¤Ï¡¢¤½¤ÎξÊý) ¤Ç½¤¾þ¤Ç¤­¤Þ¤¹¡£

ÇÉÀ¸·¿¤Î·¿½¤¾þ»Ò

·¿½¤¾þ»Ò¤Ï·¿Ì¾¤ÈÇÉÀ¸·¿¤òÊѹ¹¤·¤Þ¤¹¡£ÇÉÀ¸·¿¤Ï C ¤ÎÀë¸À¤Î°ìÉô¤Ç¤¢¤ê¡¢²¿ÅÙ¤âŬÍѤ¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢¤è¤êÊ£»¨¤Ê·¿ (¥Ý¥¤¥ó¥¿¡¢ÇÛÎó¡¢´Ø¿ô¡¢¹½Â¤ÂΡ¢¶¦ÍÑÂÎ) ¤ò¹½ÃۤǤ­¤Þ¤¹¡£´Ø¿ô¤ò½ü¤­¡¢1 ¤Ä¤Þ¤¿¤ÏξÊý¤Î·¿½¤¾þ»Ò¤ò»ÈÍѤ¹¤ë¤È¡¢ÇÉÀ¸·¿¤ÎÆ°ºî¤òÊѹ¹¤Ç¤­¤Þ¤¹¡£

¤¿¤È¤¨¤Ð¡¢¼¡¤ò¸«¤Æ¤¯¤À¤µ¤¤¡£

const int five = 5;


¤³¤ì¤Ï¡¢·¿¤¬ const int ¤Ç¤¢¤ê¡¢Ãͤ¬Àµ¤·¤¤¥×¥í¥°¥é¥à¤Ë¤è¤Ã¤ÆÊѹ¹¤µ¤ì¤Ê¤¤¥ª¥Ö¥¸¥§¥¯¥È¤òÀë¸À¤·¡¢½é´ü²½¤·¤Þ¤¹¡£¥­¡¼¥ï¡¼¥É¤Î½çÈÖ¤Ï C ¤Ë¤È¤Ã¤Æ½ÅÍפǤϤ¢¤ê¤Þ¤»¤ó¡£¤¿¤È¤¨¤Ð¡¢¼¡¤ò¸«¤Æ¤¯¤À¤µ¤¤¡£¤³¤Î 2 ¤Ä¤ÎÀë¸À¤Î¸ú²Ì¤Ï¾åµ­Àë¸À¤ÈƱ¤¸¤Ç¤¹¡£

int const five = 5;


const five = 5;


¼¡¤ò¸«¤Æ¤¯¤À¤µ¤¤¡£

const int *pci = &five;


¤³¤ÎÀë¸À¤Ï¡¢·¿¤¬ const int ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë (¤Ä¤Þ¤ê¡¢°ÊÁ°Àë¸À¤µ¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤ò»Ø¤·¤Æ¤¤¤ë) ¥ª¥Ö¥¸¥§¥¯¥È¤òÀë¸À¤·¤Þ¤¹¡£¥Ý¥¤¥ó¥¿¼«¿È¤Ï½¤¾þ·¿¤ò»ý¤Á¤Þ¤»¤ó¡£¤Ä¤Þ¤ê¡¢¥Ý¥¤¥ó¥¿¤Ï½¤¾þ·¿¤ò»Ø¤¹¤¿¤á¡¢¥×¥í¥°¥é¥à¤Î¼Â¹ÔÃæ¤ËǤ°Õ¤Î int ¤ò»Ø¤¹¤è¤¦¤ËÊѹ¹¤Ç¤­¤Þ¤¹¡£pci ¤ò»ÈÍѤ·¤Æ¡¢pci ¤¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£¤³¤Î¤¿¤á¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¥­¥ã¥¹¥È¤ò»ÈÍѤ·¤Þ¤¹¡£

*(int *)pci = 17;


pci ¤¬¼ÂºÝ¤Ë const ¥ª¥Ö¥¸¥§¥¯¥È¤ò»Ø¤¹¾ì¹ç¡¢¤³¤Î¥³¡¼¥É¤ÎÆ°ºî¤Ï̤ÄêµÁ¤Ç¤¹¡£

¼¡¤ò¸«¤Æ¤¯¤À¤µ¤¤¡£

extern int *const cpi;


¤³¤ÎÀë¸À¤Ï¡¢¥×¥í¥°¥é¥àÆâ¤Î¤É¤³¤«¤Ë¡¢·¿¤¬ int ¤Ø¤Î const ¥Ý¥¤¥ó¥¿¤Ç¤¢¤ëÂç°è¥ª¥Ö¥¸¥§¥¯¥È¤ÎÄêµÁ¤¬¤¢¤ë¤³¤È¤ò°ÕÌ£¤·¤Þ¤¹¡£¤³¤Î¾ì¹ç¡¢Àµ¤·¤¤¥×¥í¥°¥é¥à¤Ç¤Ï cpi ¤ÎÃͤÏÊѹ¹¤µ¤ì¤Þ¤»¤ó¡£¤·¤«¤·¡¢cpi ¤ò»ÈÍѤ·¤Æ¡¢cpi ¤¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤¹¡£¾åµ­Àë¸À¤Ë¤ª¤¤¤Æ¡¢const ¤¬ * ¤Î¸å¤Ë¤¢¤ë¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£¼¡¤Î 2 ¤Ä¤ÎÀë¸À¤Î¸ú²Ì¤ÏƱ¤¸¤Ç¤¹¡£

typedef int *INT_PTR;
extern const INT_PTR cpi;


¾åµ­¤ÎÀë¸À¤Ï¡¢¼¡¤ÎÀë¸À¤Î¤è¤¦¤ËÏ¢·ë¤Ç¤­¤Þ¤¹¡£¤³¤Î¾ì¹ç¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Î·¿¤Ï const int ¤Ø¤Î const ¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤ÈÀë¸À¤µ¤ì¤Þ¤¹¡£

const int *const cpci;


const ¤Ï readonly ¤ò°ÕÌ£¤¹¤ë

¤Ê¤ª¡¢¥­¡¼¥ï¡¼¥É¤È¤·¤Æ¤ÏÄ̾ï const ¤è¤ê¤â readonly ¤òÁªÂò¤¹¤ë¤Û¤¦¤¬ÊØÍø¤Ç¤¹¡£¤³¤Î¤è¤¦¤Ë const ¤ò²ò¼á¤¹¤ë¤È¡¢¼¡¤Î¤è¤¦¤ÊÀë¸À¤Ï´Êñ¤ËÍý²ò¤Ç¤­¤Þ¤¹¡£

char *strcpy(char *, const char *);


¤³¤ÎÀë¸À¤Ç¤Ï¡¢2 ÈÖÌܤΥѥé¥á¡¼¥¿¤Ïʸ»úÃͤòÆɤ߼è¤ë¤¿¤á¤À¤±¤Ë»ÈÍѤµ¤ì¡¢ºÇ½é¤Î¥Ñ¥é¥á¡¼¥¿¤Ï¤½¤ÎÃͤ¬»Ø¤¹Ê¸»ú¤ò¾å½ñ¤­¤¹¤ë¤³¤È¤ò°ÕÌ£¤·¤Æ¤¤¤Þ¤¹¡£¤µ¤é¤Ë¡¢¾åµ­Îã¤Î»ö¼Â¤Ë´Ø¤ï¤é¤º¡¢cpi ¤Î·¿¤Ï const int ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢¼ÂºÝ¤Ë·¿¤¬
const int ¤ÇÀë¸À¤µ¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤ò»Ø¤·¤Æ¤¤¤Ê¤¤¤«¤®¤ê¡¢¤½¤ÎÃͤ¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È¤ÎÃͤÏÊ̤ÎÊýË¡¤ÇÊѹ¹¤Ç¤­¤Þ¤¹¡£

const ¤Î»ÈÍÑÎã

const ¤Î 2 ¤Ä¤Î¼ç¤Ê»ÈÍÑË¡¤Ï¡¢¥³¥ó¥Ñ¥¤¥ë»þ¤Ë½é´ü²½¤µ¤ì¤¿Â礭¤Ê¾ðÊó¥Æ¡¼¥Ö¥ë¤¬Ì¤Êѹ¹¤Ç¤¢¤ë¤ÈÀë¸À¤¹¤ë¤³¤È¤È¡¢¥Ý¥¤¥ó¥¿¥Ñ¥é¥á¡¼¥¿¤¬»Ø¤·¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òÊѹ¹¤·¤Ê¤¤¤³¤È¤ò»ØÄꤹ¤ë¤³¤È¤Ç¤¹¡£

ºÇ½é¤Î»ÈÍÑË¡¤Ç¤Ï¡¢Æ±¤¸¥×¥í¥°¥é¥à¤Î¾¤ÎʹԸƤӽФ·¤¬¡¢¥×¥í¥°¥é¥à¤Î¥Ç¡¼¥¿Éôʬ¤ò¶¦Í­²Äǽ¤Ë¤·¤Þ¤¹¡£¤Ä¤Þ¤ê¡¢¥Ç¡¼¥¿¤Ï¥á¥â¥ê¡¼¤ÎÆɤ߼è¤êÀìÍÑÉôʬ¤Ë¤¢¤ë¤¿¤á¡¢¤³¤ÎÉÔÊѥǡ¼¥¿¤òÊѹ¹¤·¤è¤¦¤È¤¹¤ë»î¤ß¤ò¡¢¤¢¤ë¼ïÎà¤Î¥á¥â¥ê¡¼Êݸî¾ã³²¤Ç¨ºÂ¤Ë¸¡½Ð¤Ç¤­¤Þ¤¹¡£

2 ÈÖÌܤλÈÍÑË¡¤Ç¤Ï¡¢¼Â¹ÔÃæ¤Ë¥á¥â¥ê¡¼¾ã³²¤¬È¯À¸¤¹¤ëÁ°¤Ë¡¢ÀøºßŪ¤Ê¥¨¥é¡¼¤ò¸«¤Ä¤±¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤¿¤È¤¨¤Ð¡¢¥Ì¥ëʸ»ú¤òÁÞÆþ¤Ç¤­¤Ê¤¤Ê¸»úÎó¤ËÂФ·¤Æ¡¢¤¢¤ë´Ø¿ô¤¬°ì»þŪ¤Ë¥Ì¥ëʸ»ú¤òÁÞÆþ¤·¤è¤¦¤È¤·¤¿¾ì¹ç¡¢¤½¤Î´Ø¿ô¤Ï¡¢¥³¥ó¥Ñ¥¤¥ë»þ¡¢¥Ì¥ëʸ»ú¤òÁÞÆþ¤Ç¤­¤Ê¤¤Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬ÅϤµ¤ì¤¿¤È¤­¤Ë¸¡½Ð¤µ¤ì¤Þ¤¹¡£

volatile ¤Ïʸ»úÄ̤ê¤Î²ò¼á¤ò°ÕÌ£¤¹¤ë

¤³¤ì¤Þ¤Ç¤ÎÎã¤Ç¤Ï¤¹¤Ù¤Æ const ¤ò»ÈÍѤ·¤Æ¤­¤Þ¤·¤¿¤¬¡¢¤³¤ì¤Ï const ¤¬³µÇ°Åª¤Ë´Êñ¤Ç¤¢¤ë¤¿¤á¤Ç¤¹¡£¤·¤«¤·¡¢volatile ¤Ï¤É¤Î¤è¤¦¤Ê°ÕÌ£¤Ç¤·¤ç¤¦¤«¡£volatile ¤È¤¤¤¦¸ÀÍդϡִøȯÀ­¤Î¡×¡¢¤Ä¤Þ¤ê¤¹¤°¤ËÊѤï¤Ã¤Æ¤·¤Þ¤¦¤È¤¤¤¦°ÕÌ£¤ò»ý¤Á¤Þ¤¹¡£¤½¤Î¤¿¤á¥³¥ó¥Ñ¥¤¥é¤Ç¤Ï¡¢¥³¡¼¥ÉÀ¸À®»þ¤Ë¤³¤Î¤è¤¦¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤¿¤á¤Î¥·¥ç¡¼¥È¥«¥Ã¥È¤Ï¹Ô¤ï¤ì¤Þ¤»¤ó¡£ANSI/ISO C ¤Ç¤Ï¡¢¥ª¥Ö¥¸¥§¥¯¥È¤ò volatile ½¤¾þ·¿¤È¤·¤ÆÀë¸À¤¹¤ë¤«¤É¤¦¤«¤Ï¥×¥í¥°¥é¥Þ¤ÎÀÕǤ¤Ç¤¢¤ë¤Èµ¬Äꤷ¤Æ¤¤¤Þ¤¹¡£

volatile ¤Î»ÈÍÑÎã

volatile ¤Ï¡¢Ä̾¼¡¤Î 4 ¤Ä¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ë»ÈÍѤ·¤Þ¤¹¡£

ºÇ½é¤Î 3 ¤Ä¤ÎÎã¤Ï¤¹¤Ù¤Æ¡¢ÆÃÄê¤ÎÆ°ºî¤ò¹Ô¤¦¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤Ç¤¹¡£¤Ä¤Þ¤ê¡¢¤½¤ÎÃͤϡ¢¥×¥í¥°¥é¥à¤Î¼Â¹ÔÃæ¤ÎǤ°Õ¤Î»þÅÀ¤ÇÊѹ¹¤Ç¤­¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢³°¸«¾å¤Ï̵¸Â¥ë¡¼¥×¤Ë¸«¤¨¤Þ¤¹¡£

flag = 1;
while (flag);


¤³¤ì¤Ï¡¢flag ¤¬ volatile ½¤¾þ·¿¤ò»ý¤Ä´Ö¤ÏÍ­¸ú¤Ç¤¹¡£¤ª¤½¤é¤¯¡¢¤¢¤ëÈóƱ´ü¥¤¥Ù¥ó¥È¤¬¾­Íè flag ¤ò¥¼¥í¤ËÀßÄꤹ¤ë¤³¤È¤â¤¢¤ê¤Þ¤¹¡£¤½¤ì°Ê³°¤Î¾ì¹ç¡¢flag ¤ÎÃͤϥ롼¥×ËÜÂÎÆâ¤Ç¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¤¿¤á¡¢¥³¥ó¥Ñ¥¤¥ë¥·¥¹¥Æ¥à¤Ï¾åµ­¥ë¡¼¥×¤ò¡¢´°Á´¤Ë flag ¤ÎÃͤò̵»ë¤¹¤ëËÜÅö¤Î̵¸Â¥ë¡¼¥×¤ËÊѹ¹¤Ç¤­¤Þ¤¹¡£

4 ÈÖÌܤÎÎã¤Ï¡¢setjmp ¤ò¸Æ¤Ó½Ð¤¹´Ø¿ô¤ËÂФ·¤Æ¶É½êŪ¤ÊÊÑ¿ô¤ò´Þ¤ó¤Ç¤¤¤ë¤¿¤á¡¢¤è¤êÊ£»¨¤Ç¤¹¡£setjmp ¤È longjmp ¤ÎÆ°ºî¤Ë¤Ä¤¤¤Æ¤ÎºÙ»úÉôʬ¤Ë¤Ï¡¢4 ÈÖÌܤÎÎã¤Ë°ìÃפ¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤ÎÃͤÏÊݾڤµ¤ì¤Ê¤¤¤È¤¤¤¦Ãíµ­¤¬¤¢¤ê¤Þ¤¹¡£¤â¤Ã¤È¤â˾¤Þ¤·¤¤Æ°ºî¤ò¹Ô¤¦¤¿¤á¤Ë¤Ï¡¢setjmp ¤ò¸Æ¤Ó½Ð¤¹´Ø¿ô¤È longjmp ¤ò¸Æ¤Ó½Ð¤¹´Ø¿ô¤Î´Ö¤Ç¡¢longjmp ¤¬¤¹¤Ù¤Æ¤Î¥¹¥¿¥Ã¥¯¥Õ¥ì¡¼¥à¤ò¸¡ºº¤·¤Æ¡¢Êݸ¤µ¤ì¤¿¥ì¥¸¥¹¥¿ÃͤÈÈæ³Ó¤¹¤ë¤³¤È¤¬É¬ÍפǤ¹¡£¥¹¥¿¥Ã¥¯¥Õ¥ì¡¼¥à¤ÏÈóƱ´üŪ¤ËºîÀ®¤µ¤ì¤ë²ÄǽÀ­¤¬¤¢¤ë¤¿¤á¡¢¤³¤Îºî¶È¤Ï¤è¤êÆñ¤·¤¯¤Ê¤ê¤Þ¤¹¡£

¼«Æ°¥ª¥Ö¥¸¥§¥¯¥È¤ò volatile ½¤¾þ·¿¤ÇÀë¸À¤·¤¿¤È¤­¡¢¥³¥ó¥Ñ¥¤¥ë¥·¥¹¥Æ¥à¤Ï¡¢¥×¥í¥°¥é¥Þ¤¬½ñ¤¤¤¿¤â¤Î¤È´°Á´¤Ë°ìÃפ¹¤ë¥³¡¼¥É¤òÀ¸À®¤·¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢¤³¤Î¤è¤¦¤Ê¼«Æ°¥ª¥Ö¥¸¥§¥¯¥È¤ËÂФ¹¤ëºÇ¿·¤ÎÃͤϾï¤Ë¡¢¥ì¥¸¥¹¥¿¤Ç¤Ï¤Ê¤¯¡¢¥á¥â¥ê¡¼Æâ¤Ë¸ºß¤·¤Þ¤¹¡£¤½¤·¤Æ¡¢longjmp ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤­¤ËºÇ¿·¤Ç¤¢¤ë¤³¤È¤¬Êݾڤµ¤ì¤Þ¤¹¡£

Ê£¿ô¥Ð¥¤¥Èʸ»ú¤È¥ï¥¤¥Éʸ»ú

ºÇ½é¤Ë¡¢ANSI/ISO C ¤Î¹ñºÝ²½¤Ï¥é¥¤¥Ö¥é¥ê´Ø¿ô¤À¤±¤Ë±Æ¶Á¤¬¤¢¤ê¤Þ¤·¤¿¡£¤·¤«¤·¡¢¹ñºÝ²½¤ÎºÇ½ªÃʳ¬ (Ê£¿ô¥Ð¥¤¥Èʸ»ú¤È¥ï¥¤¥Éʸ»ú) ¤Ï¸À¸ì°À­¤Ë¤â±Æ¶Á¤·¤Þ¤¹¡£

¥¢¥¸¥¢¸À¸ì¤ÏÊ£¿ô¥Ð¥¤¥Èʸ»ú¤òɬÍפȤ¹¤ë

¥¢¥¸¥¢¸À¸ì¤ò»ÈÍѤ¹¤ë¥³¥ó¥Ô¥å¡¼¥¿´Ä¶­¤Ë¤ª¤±¤ë´ðËÜŪ¤ÊÆñ¤·¤µ¤Ï¡¢ËÄÂç¤Ê¿ô¤Îɽ°Õʸ»ú¤òÆþ½ÐÎϤ·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤³¤È¤Ç¤¹¡£Ä̾ï¤Î¥³¥ó¥Ô¥å¡¼¥¿¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤ÎÀ©¸ÂÆâ¤ÇÆ°ºî¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¤³¤Î¤è¤¦¤Êɽ°Õʸ»ú¤Ï¥Ð¥¤¥È¥·¡¼¥±¥ó¥¹¤È¤·¤ÆÉä¹æ²½¤·¤Þ¤¹¡£´ØÏ¢¤¹¤ë¥ª¥Ú¥ì¡¼¥Æ¥£¥ó¥°¥·¥¹¥Æ¥à¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¡¢¤ª¤è¤ÓüËö¤Ï¡¢¤³¤Î¤è¤¦¤Ê¥Ð¥¤¥È¥·¡¼¥±¥ó¥¹¤ò¸Ä¡¹¤Îɽ°Õʸ»ú¤È¤·¤Æǧ¼±¤·¤Þ¤¹¡£¤µ¤é¤Ë¡¢¤¹¤Ù¤Æ¤Î¤³¤Î¤è¤¦¤ÊÉä¹æ²½¤Ë¤è¤Ã¤Æ¡¢Ä̾ï¤Î 1 ¥Ð¥¤¥Èʸ»ú¤òɽ°Õʸ»ú¤Î¥Ð¥¤¥È¥·¡¼¥±¥ó¥¹¤Èº®¹ç¤Ç¤­¤Þ¤¹¡£¸Ä¡¹¤Îɽ°Õʸ»ú¤òǧ¼±¤¹¤ë¤³¤È¤¬¤É¤Î¤¯¤é¤¤º¤Æñ¤Ç¤¢¤ë¤«¤Ï¡¢»ÈÍѤ¹¤ëÉä¹æ²½Êý¼°¤Ë¤è¤Ã¤Æ°Û¤Ê¤ê¤Þ¤¹¡£

¡ÖÊ£¿ô¥Ð¥¤¥Èʸ»ú¡×¤Ï¡¢ANSI/ISO C ¤ÎÄêµÁ¤Ç¤Ï¡¢»ÈÍѤ¹¤ëÉä¹æ²½Êý¼°¤Î¼ïÎà¤Ë´Ø·¸¤Ê¤¯¡¢É½°Õʸ»ú¤òÉä¹æ²½¤¹¤ë¥Ð¥¤¥È¥·¡¼¥±¥ó¥¹¤ò¼¨¤·¤Þ¤¹¡£¤¹¤Ù¤Æ¤ÎÊ£¿ô¥Ð¥¤¥Èʸ»ú¤Ï¡Ö³Èĥʸ»ú¥»¥Ã¥È¡×¤Ë°¤·¤Þ¤¹¡£Ä̾ï¤Î 1 ¥Ð¥¤¥Èʸ»ú¤Ï¡¢Ã±¤ËÊ£¿ô¥Ð¥¤¥Èʸ»ú¤ÎÆÃÊ̤ʥ±¡¼¥¹¤Ç¤¹¡£Éä¹æ²½¤ËɬÍפÊÍ£°ì¤Î¾ò·ï¤Ï¡¢¤É¤ÎÊ£¿ô¥Ð¥¤¥Èʸ»ú¤â¥Ì¥ëʸ»ú¤òÉä¹æ²½¤Î°ìÉô¤È¤·¤Æ»ÈÍѤǤ­¤Ê¤¤¤È¤¤¤¦¤³¤È¤Ç¤¹¡£

ANSI/ISO C ¤Ç¤Ï¡¢¥×¥í¥°¥é¥à¤Î¥³¥á¥ó¥È¡¢Ê¸»úÎó¥ê¥Æ¥é¥ë¡¢Ê¸»úÄê¿ô¡¢¤ª¤è¤Ó¥Ø¥Ã¥À¡¼Ì¾¤¬¤¹¤Ù¤ÆÊ£¿ô¥Ð¥¤¥Èʸ»ú¤Î¥·¡¼¥±¥ó¥¹¤Ç¤¢¤ë¤Èµ¬Äꤵ¤ì¤Æ¤¤¤Þ¤¹¡£

Éä¹æ²½¤Î¼ïÎà

Éä¹æ²½Êý¼°¤Ï 2 ¤Ä¤Î¼ïÎà¤Ëʬ¤±¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£1 ¤Ä¤Ï¡¢³ÆÊ£¿ô¥Ð¥¤¥Èʸ»ú¤¬¼«¸Ê¼±ÊÌÀ­¤ò»ý¤ÄÊý¼°¤Ç¤¹¡£¤Ä¤Þ¤ê¡¢¤É¤ÎÊ£¿ô¥Ð¥¤¥Èʸ»ú¤â´Êñ¤Ë 2 ¤Ä¤ÎÊ£¿ô¥Ð¥¤¥Èʸ»ú¤Î´Ö¤ËÁÞÆþ¤Ç¤­¤Þ¤¹¡£

¤â¤¦ 1 ¤Ä¤Ï¡¢ÆÃÊ̤ʥ·¥Õ¥È¥Ð¥¤¥È¤Î¸ºß¤¬¸å³¤Î¥Ð¥¤¥È¤Î²ò¼á¤òÊѹ¹¤¹¤ëÊý¼°¤Ç¤¹¡£¤¿¤È¤¨¤Ð¡¢¤¢¤ë¥­¥ã¥é¥¯¥¿Ã¼Ëö¤Ç¹ÔÉÁ²è¥â¡¼¥É¤òÀÚ¤êÂؤ¨¤ë¤¿¤á¤Ë»ÈÍѤ¹¤ëÊý¼°¤¬¤½¤¦¤Ç¤¹¡£¤³¤Î¥·¥Õ¥È¾õÂְ͸Éä¹æ²½¤Ë¤è¤ëÊ£¿ô¥Ð¥¤¥Èʸ»ú¤Ç½ñ¤«¤ì¤¿¥×¥í¥°¥é¥à¤Î¾ì¹ç¡¢ANSI/ISO C ¤Ç¤Ï¡¢¥³¥á¥ó¥È¡¢Ê¸»úÎó¥ê¥Æ¥é¥ë¡¢Ê¸»úÄê¿ô¡¢¤ª¤è¤Ó¥Ø¥Ã¥À¡¼Ì¾¤Î»Ï¤Þ¤ê¤È½ª¤ï¤ê¤¬¤¹¤Ù¤Æ¥·¥Õ¥È¤Ê¤·¾õÂ֤Ǥʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤¤Èµ¬Äꤷ¤Æ¤¤¤Þ¤¹¡£

¥ï¥¤¥Éʸ»ú

Ê£¿ô¥Ð¥¤¥Èʸ»ú¤Î½èÍý¤ÇÉÔÅԹ礬ȯÀ¸¤·¤¿¾ì¹ç¤Ï¡¢¤¹¤Ù¤Æ¤Îʸ»ú¤ò°ìÄê¤Î¥Ð¥¤¥È¿ô¤Þ¤¿¤Ï¥Ó¥Ã¥È¿ô¤Ë¤¹¤ë¤³¤È¤Ç²ò·è¤Ç¤­¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£¤³¤Î¤è¤¦¤Êʸ»ú¥»¥Ã¥È¤Ë¤Ï²¿Àé¤Þ¤¿¤Ï²¿Ëü¤â¤Îɽ°Õʸ»ú¤¬¤¢¤ë¤¿¤á¡¢¤³¤ì¤é¤¹¤Ù¤Æ¤òÊÝ»ý¤¹¤ë¤Ë¤Ï¡¢Â礭¤µ¤¬ 16 ¥Ó¥Ã¥È¤Þ¤¿¤Ï 32 ¥Ó¥Ã¥È¤ÎÀ°¿ôÃͤò»ÈÍѤ·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó (´°Á´¤ÊÃæ¹ñ¸ì¤Ë¤Ï 65,000 °Ê¾å¤â¤Îɽ°Õʸ»ú¤¬¤¢¤ê¤Þ¤¹)¡£ANSI/ISO C ¤Ë¤Ï¡¢³Èĥʸ»ú¥»¥Ã¥È¤Î¤¹¤Ù¤Æ¤òÊÝ»ý¤¹¤ë¤¿¤á¤Ë½½Ê¬¤ÊÂ礭¤µ¤ò»ý¤Ä¼ÂÁõÄêµÁ¤ÎÀ°¿ô·¿¤È¤·¤Æ¡¢typedef ̾ wchar_t ¤¬¤¢¤ê¤Þ¤¹¡£

³Æ¥ï¥¤¥Éʸ»ú¤Ë¤Ï¡¢¤½¤ì¤ËÂбþ¤¹¤ëÊ£¿ô¥Ð¥¤¥Èʸ»ú¤¬¤¢¤ê¤Þ¤¹ (¤½¤ÎµÕ¤â¤¢¤ê¤Þ¤¹)¡£¤Ä¤Þ¤ê¡¢Ä̾ï¤Î 1 ¥Ð¥¤¥Èʸ»ú¤ËÂбþ¤¹¤ë¥ï¥¤¥Éʸ»ú¤Ï¡¢¤½¤Î 1 ¥Ð¥¤¥ÈÃͤÈƱ¤¸Ãͤò»ý¤ÄɬÍפ¬¤¢¤ê¤Þ¤¹ (¥Ì¥ëʸ»ú¤â´Þ¤à)¡£¤·¤«¤·¡¢¥Þ¥¯¥í EOF ¤¬ char ¤È¤·¤Æɽ¸½¤Ç¤­¤Ê¤¤¤è¤¦¤Ë¡¢¥Þ¥¯¥í EOF ¤ÎÃͤ¬ wchar_t ¤Ë³ÊǼ¤Ç¤­¤ë¤«¤É¤¦¤«¤ÏÊݾڤµ¤ì¤Æ¤¤¤Þ¤»¤ó¡£

ÊÑ´¹´Ø¿ô

ANSI/ISO C ¤Ç¤Ï¡¢Ê£¿ô¥Ð¥¤¥Èʸ»ú¤È¥ï¥¤¥Éʸ»ú¤ò´ÉÍý¤¹¤ë¤¿¤á¤Ë¡¢5 ¤Ä¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤òµ¬Äꤷ¤Æ¤¤¤Þ¤¹¡£

ɽ 7-2   Ê£¿ô¥Ð¥¤¥Èʸ»ú¤ÎÊÑ´¹´Ø¿ô
mblen() ¼¡¤ÎÊ£¿ô¥Ð¥¤¥Èʸ»ú¤ÎŤµ
mbtowc() Ê£¿ô¥Ð¥¤¥Èʸ»ú¤«¤é¥ï¥¤¥Éʸ»ú¤ËÊÑ´¹¤¹¤ë
wctomb() ¥ï¥¤¥Éʸ»ú¤«¤éÊ£¿ô¥Ð¥¤¥Èʸ»ú¤ËÊÑ´¹¤¹¤ë
mbstowcs() Ê£¿ô¥Ð¥¤¥Èʸ»ú¤Îʸ»úÎ󤫤é¥ï¥¤¥Éʸ»ú¤Îʸ»úÎó¤ËÊÑ´¹¤¹¤ë
wcstombs() ¥ï¥¤¥Éʸ»ú¤Îʸ»úÎ󤫤éÊ£¿ô¥Ð¥¤¥Èʸ»ú¤Îʸ»úÎó¤ËÊÑ´¹¤¹¤ë


¤³¤ì¤é¤Î´Ø¿ô¤Î¤¹¤Ù¤Æ¤ÎÆ°ºî¤Ï¡¢¥í¥±¡¼¥ë¤Ë¤è¤Ã¤Æ°Û¤Ê¤ê¤Þ¤¹¡£
¡Ösetlocale() ´Ø¿ô¡×¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£

¥¢¥¸¥¢»Ô¾ì¸þ¤±¤Ë¥³¥ó¥Ñ¥¤¥ë¥·¥¹¥Æ¥à¤òÄ󶡤¹¤ë¥Ù¥ó¥À¡¼¤¬¡¢¤è¤ê¿¤¯¤Îʸ»úÎóÍÑ´Ø¿ô¤òÄ󶡤·¡¢¥ï¥¤¥Éʸ»ú¤Îʸ»úÎó¤Î½èÍý¤¬´Êñ¤Ë¤Ê¤ë¤³¤È¤¬´üÂÔ¤µ¤ì¤Þ¤¹¡£¤·¤«¤·¡¢¤Û¤È¤ó¤É¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ç¤Ï¡¢Ê£¿ô¥Ð¥¤¥Èʸ»ú¤È¥ï¥¤¥Éʸ»ú´Ö¤ÎÊÑ´¹¤ÏɬÍפ¢¤ê¤Þ¤»¤ó¡£¤¿¤È¤¨¤Ð¡¢Ê£¿ô¥Ð¥¤¥Èʸ»ú¤ÇÆɤ߼è¤ê¤È½ñ¤­¹þ¤ß¤ò¹Ô¤¦¥×¥í¥°¥é¥à (diff ¤Ê¤É) ¤Ï¡¢¥Ð¥¤¥Èñ°Ì¤Ç¤ÎÀµ³Î¤Ê°ìÃפò¸¡ºº¤¹¤ë¤³¤È¤À¤±¤¬É¬ÍפǤ¹¡£Àµµ¬É½¸½¤Ë¤è¤ë¥Ñ¥¿¡¼¥ó°ìÃפò»ÈÍѤ¹¤ë¤è¤êÊ£»¨¤Ê¥×¥í¥°¥é¥à (grep ¤Ê¤É) ¤Ï¡¢Ê£¿ô¥Ð¥¤¥Èʸ»ú¤òÍý²ò¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£¤·¤«¤·¡¢Ê£¿ô¥Ð¥¤¥Èʸ»ú¤òÍý²ò¤¹¤ëɬÍפ¬¤¢¤ë¤Î¤Ï¡¢Àµµ¬É½¸½¤ò´ÉÍý¤¹¤ë´Ø¿ô¤À¤±¤Ç¤¹¡£¥×¥í¥°¥é¥à grep ¼«¿È¤Ë¤Ï¡¢Â¾¤ÎÆÃÊ̤ÊÊ£¿ô¥Ð¥¤¥Èʸ»ú½èÍý¤ÏɬÍפ¢¤ê¤Þ¤»¤ó¡£

C ¸À¸ì¤Îµ¡Ç½

¥¢¥¸¥¢¸À¸ì´Ä¶­¤Ë¤ª¤¤¤Æ¥×¥í¥°¥é¥Þ¤¬¤è¤ê½ÀÆð¤Ë¥×¥í¥°¥é¥à¤òÁȤि¤á¤Ë¡¢ANSI/ISO C ¤Ç¤Ï¡¢¥ï¥¤¥Éʸ»úÄê¿ô¤È¥ï¥¤¥Éʸ»úÎó¥ê¥Æ¥é¥ë¤òÄ󶡤·¤Æ¤¤¤Þ¤¹¡£¤³¤Î 2 ¤Ä¤Î·Á¼°¤Ï¡¢Ä¾Á°¤Ëʸ»ú¡ÖL¡×¤ÎÀÜƬ¼­¤¬ÉÕ¤¯¤³¤È¤ò½ü¤­¡¢Ä̾ï¤Î (¥ï¥¤¥É¤Ç¤Ê¤¤) ¥Ð¡¼¥¸¥ç¥ó¤ÈƱ¤¸¤Ç¤¹¡£

`x' Ä̾ï¤Îʸ»úÄê¿ô

`¥' Ä̾ï¤Îʸ»úÄê¿ô

L'x' ¥ï¥¤¥Éʸ»úÄê¿ô

L'¥' ¥ï¥¤¥Éʸ»úÄê¿ô

"abc¥xyz" Ä̾ï¤Îʸ»úÎó¥ê¥Æ¥é¥ë

L"abcxyz" ¥ï¥¤¥Éʸ»úÎó¥ê¥Æ¥é¥ë

Ê£¿ô¥Ð¥¤¥Èʸ»ú¤Ï¡¢Ä̾ï¤È¥ï¥¤¥É¤ÎξÊý¤Î¥Ð¡¼¥¸¥ç¥ó¤ÇÍ­¸ú¤Ç¤¹¡£É½µ­Ê¸»ú \ ¤òÀ¸À®¤¹¤ë¤¿¤á¤ËɬÍפʥХ¤¥È¥·¡¼¥±¥ó¥¹¤ÏÉä¹æ²½¤Ë¤è¤Ã¤Æ°Û¤Ê¤ê¤Þ¤¹¡£¤·¤«¤·¡¢Ê¸»úÄê¿ô `\' ¤¬Ê£¿ô¤Î¥Ð¥¤¥È¤«¤é¹½À®¤µ¤ì¤ë¾ì¹ç¡¢'ab' ¤¬¼ÂÁõ¤Ë¤è¤êÄêµÁ¤µ¤ì¤ë¤Î¤ÈƱÍͤˡ¢¤½¤ÎÃͤϼÂÁõ¤Ë¤è¤êÄêµÁ¤µ¤ì¤Þ¤¹¡£¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤ò½ü¤­¡¢Ä̾ï¤Îʸ»úÎó¥ê¥Æ¥é¥ë¤Ë¤Ï¡¢°úÍÑÉä¤Î´Ö¤Ë»ØÄꤵ¤ì¤¿¤â¤Î¤ÈƱ¤¸¥Ð¥¤¥È¿ô (»ØÄꤷ¤¿¤¹¤Ù¤Æ¤ÎÊ£¿ô¥Ð¥¤¥Èʸ»ú¤Î¥Ð¥¤¥È¿ô¤â´Þ¤à) ¤¬´Þ¤Þ¤ì¤Þ¤¹¡£

¥³¥ó¥Ñ¥¤¥ë¥·¥¹¥Æ¥à¤¬¥ï¥¤¥Éʸ»úÄê¿ô¤Þ¤¿¤Ï¥ï¥¤¥Éʸ»úÎó¥ê¥Æ¥é¥ë¤ò¸¡½Ð¤·¤¿¤È¤­¡¢³ÆÊ£¿ô¥Ð¥¤¥Èʸ»ú¤Ï (mbtowc() ´Ø¿ô¤ò¸Æ¤Ó½Ð¤·¤¿¤è¤¦¤Ë) ¥ï¥¤¥Éʸ»ú¤ËÊÑ´¹¤µ¤ì¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢L'\' ¤Î·¿¤Ï wchar_t ¤Ç¤¹¡£abc¥xyz ¤Î·¿¤ÏŤµ¤¬ 8 ¤Î wchar_t ¤ÎÇÛÎó¤Ç¤¹¡£Ä̾ï¤Îʸ»úÎó¥ê¥Æ¥é¥ë¤ÈƱÍͤˡ¢³Æ¥ï¥¤¥Éʸ»úÎó¥ê¥Æ¥é¥ë¤Ï¡¢Ãͤ¬¥¼¥í¤Î;ʬ¤ÊÍ×ÁǤ¬Äɲ䵤ì¤Þ¤¹¡£¤·¤«¤·¡¢¤³¤ÎÍ×ÁǤϡ¢¥¼¥í¤ÎÃͤò»ý¤Ä wchar_t ¤Ç¤¹¡£

Ä̾ï¤Îʸ»úÎó¥ê¥Æ¥é¥ë¤¬Ê¸»úÇÛÎó½é´ü²½¤Î´Êñ¤ÊÊýË¡¤È¤·¤Æ»ÈÍѤǤ­¤ë¤Î¤ÈƱÍͤˡ¢¥ï¥¤¥Éʸ»úÎó¥ê¥Æ¥é¥ë¤â wchar_t ÇÛÎó¤ò½é´ü²½¤¹¤ë¤¿¤á¤Ë»ÈÍѤǤ­¤Þ¤¹¡£

wchar_t *wp = L"a¥z";
wchar_t x[] = L"a¥z";
wchar_t y[] = {L'a', L'¥', L'z', 0};
wchar_t z[] = {'a', L'¥', 'z', '\0'};


¾åµ­¤ÎÎã¤Ç¤Ï¡¢3 ¤Ä¤ÎÇÛÎó x¡¢y¡¢z ¤È¡¢wp ¤¬»Ø¤¹ÇÛÎó¤ÎŤµ¤ÏƱ¤¸¤Ç¤¹¡£¤¹¤Ù¤Æ¤ÎÇÛÎó¤ÏƱ¤¸Ãͤǽé´ü²½¤µ¤ì¤Þ¤¹¡£

ºÇ¸å¤Ë¡¢Ä̾ï¤Îʸ»úÎó¥ê¥Æ¥é¥ë¤ÈƱÍͤˡ¢ÎÙÀܤ¹¤ë¥ï¥¤¥Éʸ»úÎó¥ê¥Æ¥é¥ë¤ÏÏ¢·ë¤µ¤ì¤Þ¤¹¡£¤·¤«¤·¡¢Ä̾ï¤Îʸ»úÎó¥ê¥Æ¥é¥ë¤È¥ï¥¤¥Éʸ»úÎó¥ê¥Æ¥é¥ë¤¬ÎÙÀܤ¹¤ë¾ì¹ç¡¢¤½¤ÎÆ°ºî¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£¤³¤Î¤è¤¦¤ÊÏ¢·ë¤¬¼õ¤±ÉÕ¤±¤é¤ì¤Ê¤¤¾ì¹ç¡¢¥³¥ó¥Ñ¥¤¥é¤Ï¥¨¥é¡¼¤òȯ¹Ô¤¹¤ëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£

ɸ½à¥Ø¥Ã¥À¡¼¤ÈͽÌó̾

ɸ½à²½ºî¶È¤Î½é´ü¤ÎÃʳ¬¤Ë¤ª¤¤¤Æ ANSI/ISO µ¬³Ê°Ñ°÷²ñ¤Ï¡¢¥é¥¤¥Ö¥é¥ê´Ø¿ô¡¢¥Þ¥¯¥í¡¢¤ª¤è¤Ó¥Ø¥Ã¥À¡¼¥Õ¥¡¥¤¥ë¤ò ANSI/ISO C ¤Î°ìÉô¤È¤·¤Æ´Þ¤à¤³¤È¤òÁªÂò¤·¤Þ¤·¤¿¡£¤³¤Î·èÄê¤ÏËÜÅö¤Ë°Ü¿¢²Äǽ¤Ê C ¥×¥í¥°¥é¥à¤ò½ñ¤¯¤¿¤á¤ËɬÍפǤ·¤¿¤¬¡¢°ìÊý¤Ç¤Ï¡¢¥æ¡¼¥¶¡¼¤«¤é ANSI/ISO C ¤ËÂФ·¤Æ¤â¤Ã¤È¤âÈÝÄêŪ¤Ê°Õ¸« (¤Ä¤Þ¤ê¡¢Í½Ìó̾¤¬Â¿¤¹¤®¤ë) ¤¬½Ð¤ëÍýͳ¤È¤Ê¤ê¤Þ¤·¤¿¡£

¤³¤ÎÀá¤Ç¤Ï¡¢¤µ¤Þ¤¶¤Þ¤ÊͽÌó̾¤Î¥«¥Æ¥´¥ê¤È¤½¤ÎͽÌó̾¤¬É¬ÍפʴðËÜŪ¤ÊÍýͳ¤ò¼¨¤·¤Þ¤¹¡£ºÇ¸å¤Ë¤Ï¡¢¥×¥í¥°¥é¥à¤ÇͽÌó̾¤ò»ÈÍѤ·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤¿¤á¤Îµ¬Â§¤ò¼¨¤·¤Þ¤¹¡£

Ä´À°¤Î·Ð°Þ

´û¸¤Î¼ÂÁõ¤Ë°ìÃפµ¤»¤ë¤¿¤á¡¢ANSI/ISO C °Ñ°÷²ñ¤Ï printf ¤ä NULL ¤Ê¤É¤Î̾Á°¤òÁªÂò¤·¤Þ¤·¤¿¡£¤·¤«¤·¤½¤Î·ë²Ì¡¢C ¥×¥í¥°¥é¥à¤Ç¼«Í³¤Ë»ÈÍѤǤ­¤ë̾Á°¤¬¸º¤ê¤Þ¤·¤¿¡£

°ìÊý¡¢É¸½à²½°ÊÁ°¤Ç¤Ï¡¢¼ÂÁõ¼Ô¤Ï¼«Í³¤Ë¿·¤·¤¤¥­¡¼¥ï¡¼¥É¤ò¥³¥ó¥Ñ¥¤¥é¤ËÄɲä·¡¢¿·¤·¤¤Ì¾Á°¤ò¥Ø¥Ã¥À¡¼¤ËÄɲäǤ­¤Þ¤·¤¿¡£¤·¤¿¤¬¤Ã¤Æ¡¢¤É¤Î¥×¥í¥°¥é¥à¤â¥ê¥ê¡¼¥¹¤¬ÊѤï¤ë¤À¤±¤Ç¥³¥ó¥Ñ¥¤¥ë¤Ç¤­¤ë¤«¤É¤¦¤«Êݾڤµ¤ì¤º¡¢¤Þ¤·¤Æ¡¢°Û¤Ê¤ë¥Ù¥ó¥À¡¼¤Î¼ÂÁõ´Ö¤Ç¤Ï°Ü¿¢¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£

¤½¤Î·ë²Ì¡¢°Ñ°÷²ñ¤Ï ANSI/ISO C ¤Ë½àµò¤¹¤ë¼ÂÁõ¤Ç¤Ï;ʬ¤Ê̾Á°¤ò»ÈÍѤ·¤Æ¤Ï¤Ê¤é¤Ê¤¤ (ÆÃÄê¤Î·Á¼°¤Î̾Á°¤ò½ü¤¯) ¤È¤¤¤¦¸·¤·¤¤·èÄê¤ò²¼¤·¤Þ¤·¤¿¡£¤³¤Î·èÄê¤Ë¤Ï¡¢¤Û¤È¤ó¤É¤Î C ¥³¥ó¥Ñ¥¤¥ë¥·¥¹¥Æ¥à¤¬¤Û¤Ü½àµò¤Ç¤­¤Þ¤¹¡£¤·¤«¤·¡¢É¸½à¥Ø¥Ã¥À¡¼¤Ë¤Ï¡¢32 ¸Ä¤Î¥­¡¼¥ï¡¼¥É¤ÈÌó 250 ¸Ä¤Î̾Á°¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£¤É¤Î¥­¡¼¥ï¡¼¥É¤Þ¤¿¤Ï̾Á°¤âÆÃÄê¤Î̿̾¥Ñ¥¿¡¼¥ó¤Ë½¾¤Ã¤Æ¤¤¤ë¤È¤Ï¸Â¤ê¤Þ¤»¤ó¡£

ɸ½à¥Ø¥Ã¥À¡¼

ɸ½à¥Ø¥Ã¥À¡¼¤Ï¼¡¤Î¤È¤ª¤ê¤Ç¤¹¡£

ɽ 7-3   É¸½à¥Ø¥Ã¥À¡¼
assert.h
locale.h
stddef.h 
ctype.h
math.h
stdio.h 
errno.h
setjmp.h
stdlib.h 
float.h
signal.h
string.h 
limits.h
stdarg.h
time.h 


¤Û¤È¤ó¤É¤Î¼ÂÁõ¤Ç¤Ï¡¢¤µ¤é¤Ë¿¤¯¤Î¥Ø¥Ã¥À¡¼¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤·¤«¤·¡¢ANSI/ISO C ¤Ë¸·Ì©¤Ë½àµò¤¹¤ë¥×¥í¥°¥é¥à¤¬»ÈÍѤǤ­¤ë¤Î¤Ï¡¢¾åµ­¥Ø¥Ã¥À¡¼¤À¤±¤Ç¤¹¡£

¤³¤ì¤é¥Ø¥Ã¥À¡¼¤Î°ìÉô¤ÎÆâÍƤˤĤ¤¤Æ¤Ï¡¢Â¾¤Îµ¬³Ê¤Ç¤Ï¤ï¤º¤«¤Ë°Û¤Ê¤ê¤Þ¤¹¡£¤¿¤È¤¨¤Ð¡¢POSIX (IEEE 1003.1) ¤Ï¡¢fdopen ¤ò stdio.h ¤ÇÀë¸À¤¹¤ë¤è¤¦¤Ë»ØÄꤷ¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤é 2 ¤Ä¤Îµ¬³Ê¤¬¶¦Â¸¤¹¤ë¤¿¤á¤Ë¡¢POSIX ¤Ç¤Ï¡¢¤³¤Î¤è¤¦¤ÊÄɲäÎ̾Á°¤¬Â¸ºß¤¹¤ë¤³¤È¤òÊݾڤ¹¤ë¤¿¤á¤Ë¤ÏǤ°Õ¤Î¥Ø¥Ã¥À¡¼¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ëÁ°¤Ë¥Þ¥¯¥í _POSIX_SOURCE ¤ò #define ¤ÇÄêµÁ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤Èµ¬Äꤷ¤Æ¤¤¤Þ¤¹¡£X/Open ¤Î¡ØPortability Guide¡Ù¤Ë¤è¤ë¤È¡¢X/Open ¤â¤³¤Î¥Þ¥¯¥íÊý¼°¤ò»ÈÍѤ·¤Æ³ÈÄ¥¤·¤Æ¤¤¤Þ¤¹¡£X/Open ¤Î¥Þ¥¯¥í¤Ï _XOPEN_SOURCE ¤Ç¤¹¡£

ANSI/ISO C ¤Ï¡¢É¸½à¥Ø¥Ã¥À¡¼¤¬¤½¤ì¼«¿È¤À¤±¤Ç´°·ë¤·¡¢¤Ù¤­Åù (²¿ÅÙ»ØÄꤷ¤Æ¤âƱ¤¸) ¤Ç¤¢¤ë¤³¤È¤òÍ׵ᤷ¤Æ¤¤¤Þ¤¹¡£¤É¤Îɸ½à¥Ø¥Ã¥À¡¼¤â¡¢¤½¤ÎÁ°¸å¤Ç¾¤Î¥Ø¥Ã¥À¡¼¤ò #include ¤Ç¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£É¸½à¥Ø¥Ã¥À¡¼¤Ï²¿ÅÙ #include ¤Ç¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤â¡¢ÌäÂê¤ÏȯÀ¸¤·¤Þ¤»¤ó¡£ANSI/ISO C µ¬³Ê¤Ç¤Ï¡¢°ÂÁ´¤Ê¥³¥ó¥Æ¥­¥¹¥È¤Ë¤ª¤¤¤Æ¤Î¤ß¡¢É¸½à¥Ø¥Ã¥À¡¼¤ò #include ¤Ç¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤³¤È¤òÍ׵ᤷ¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢¥Ø¥Ã¥À¡¼¤Ç»ÈÍѤµ¤ì¤ë̾Á°¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¤³¤È¤¬Êݾڤµ¤ì¤Þ¤¹¡£

¼ÂÁõ¤Ç»ÈÍѤµ¤ì¤ëͽÌó̾

ANSI/ISO C µ¬³Ê¤Ï¡¢É¸½à¥é¥¤¥Ö¥é¥ê¤Ë¤Ä¤¤¤Æ¡¢¤è¤ê¿¤¯¤ÎÀ©¸Â¤ò¼ÂÁõ¤Ë²Ý¤·¤Æ¤¤¤Þ¤¹¡£²áµî¤Ë¤ª¤¤¤Æ¡¢¤Û¤È¤ó¤É¤Î¥×¥í¥°¥é¥Þ¤Ï UNIX ¥·¥¹¥Æ¥à¤Ç¤ÏÆȼ«¤Î´Ø¿ô¤Ë read ¤ä write ¤Ê¤É¤Î̾Á°¤ò»ÈÍѤ·¤Ê¤¤¤è¤¦¤Ë³Ø¤Ó¤Þ¤·¤¿¡£ANSI/ISO C ¤Ç¤Ï¡¢Í½Ì󤵤ì¤Æ¤¤¤ë̾Á°¤À¤±¤ò¼ÂÁõÆâ¤Î»²¾È¤Ç»ÈÍѤ¹¤ë¤è¤¦¤Ëµ¬Äꤷ¤Æ¤¤¤Þ¤¹¡£

¤·¤¿¤¬¤Ã¤Æ ANSI/ISO C µ¬³Ê¤Ç¤Ï¡¢¼ÂÁõ¤Ç»ÈÍѤ¹¤ë²ÄǽÀ­¤¬¤¢¤ë¤¹¤Ù¤Æ¤Î̾Á°¤Î¥µ¥Ö¥»¥Ã¥È¤¬Í½Ì󤵤ì¤Æ¤¤¤Þ¤¹¡£¤³¤Î̾Á°¤Î¥¯¥é¥¹¤Ï²¼Àþ¤Ç»Ï¤Þ¤ê¡¢¤â¤¦ 1 ¤Ä¤Î²¼Àþ¤Þ¤¿¤ÏÂçʸ»ú¤Î±Ñ»ú¤¬Â³¤¯¼±Ê̻Ҥ«¤é¹½À®¤µ¤ì¤Þ¤¹¡£¤³¤Î̾Á°¤Î¥¯¥é¥¹¤Ï¡¢¼¡¤ÎÀµµ¬É½¸½¤Ë°ìÃפ¹¤ë¤¹¤Ù¤Æ¤Î̾Á°¤ò´Þ¤ß¤Þ¤¹¡£

_[_A-Z][0-9_a-zA-Z]*


¸·Ì©¤Ë¤Ï¡¢¥×¥í¥°¥é¥à¤¬¤³¤Î¤è¤¦¤Ê¼±Ê̻Ҥò»ÈÍѤ¹¤ë¾ì¹ç¡¢¤½¤ÎÆ°ºî¤Ï̤ÄêµÁ¤Ç¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢_POSIX_SOURCE (¤Þ¤¿¤Ï¡¢_XOPEN_SOURCE) ¤ò»ÈÍѤ¹¤ë¥×¥í¥°¥é¥à¤ÎÆ°ºî¤Ï̤ÄêµÁ¤Ç¤¹¡£

¤¿¤À¤·¡¢Æ°ºî¤¬¤É¤ì¤°¤é¤¤Ì¤ÄêµÁ¤Ê¤Î¤«¤Ï°Û¤Ê¤ê¤Þ¤¹¡£POSIX ½àµò¤Î¼ÂÁõ¤Ç _POSIX_SOURCE ¤ò»ÈÍѤ¹¤ë¾ì¹ç¡¢¥æ¡¼¥¶¡¼¤Î¥×¥í¥°¥é¥à¤Î̤ÄêµÁ¤ÎÆ°ºî¤¬ÆÃÄê¤Î¥Ø¥Ã¥À¡¼Æâ¤ËÄɲ䵤줿ÆÃÄê¤Î̾Á°¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤ë¤³¤È¤È¡¢¼õ¤±Æþ¤ì¤é¤ì¤ëɸ½à¤Ë¥æ¡¼¥¶¡¼¤Î¥×¥í¥°¥é¥à¤¬½àµò¤·¤Æ¤¤¤ë¤³¤È¤Ïͽ¬¤Ç¤­¤Þ¤¹¡£ANSI/ISO C µ¬³Ê¤Ë¤ª¤±¤ë¤³¤Î¸Î°Õ¤ÎÈ´¤±Æ»¤Ë¤è¤ê¡¢¼ÂÁõ¤Ï³°¸«¾å¸ß´¹À­¤Î¤Ê¤¤»ÅÍͤ˽àµò¤Ç¤­¤Þ¤¹¡£°ìÊý¡¢POSIX µ¬³Ê¤Ë½àµò¤·¤Ê¤¤¼ÂÁõ¤Ï¡¢_POSIX_SOURCE ¤Ê¤É¤Î̾Á°¤ËÁø¶ø¤·¤¿¤È¤­¡¢Ç¤°Õ¤ÎÊýË¡¤ÇÆ°ºî¤Ç¤­¤Þ¤¹¡£

ANSI/ISO C µ¬³Ê¤Ç¤Ï¡¢²¼Àþ¤Ç»Ï¤Þ¤ë¾¤Î¤¹¤Ù¤Æ¤Î̾Á°¤¬ (¶É½êŪ¤Ê¥¹¥³¡¼¥×¤Ç¤Ï¤Ê¤¯) ¥Ø¥Ã¥À¡¼¥Õ¥¡¥¤¥ë¤Ë¤ª¤±¤ëÄ̾ï¤Î¥Õ¥¡¥¤¥ë¤Î¥¹¥³¡¼¥×¤Î¼±Ê̻ҤȤ·¤Æ¡¢¤ª¤è¤Ó¹½Â¤ÂΤȶ¦ÍÑÂΤΥ¿¥°¤È¤·¤Æ»ÈÍѤ¹¤ë¤¿¤á¤ËͽÌ󤵤ì¤Æ¤¤¤Þ¤¹¡£½¾ÍèÄ̤ꡢ_filbuf ¤È _doprnt ¤È¤¤¤¦Ì¾Á°¤Î´Ø¿ô¤Ë¤è¤ê¥é¥¤¥Ö¥é¥ê¤Î±£¤ì¤¿Éôʬ¤ò¼ÂÁõ¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤¹¡£

³ÈÄ¥ÍѤÎͽÌó̾

ÌÀ¼¨Åª¤ËͽÌ󤵤줿¤¹¤Ù¤Æ¤Î̾Á°¤Ë²Ã¤¨¤Æ¡¢ANSI/ISO C µ¬³Ê¤Ï¡¢¼¡¤ÎÆÃÄê¤Î¥Ñ¥¿¡¼¥ó¤Ë°ìÃפ¹¤ë̾Á°¤ò (¼ÂÁõ¤È¾­Íè¤Îµ¬³ÊÍѤË) ͽÌ󤷤Ƥ¤¤Þ¤¹¡£

ɽ 7-4   ³ÈÄ¥ÍѤÎͽÌó̾
¥Õ¥¡¥¤¥ë ͽÌó̾¤Î¥Ñ¥¿¡¼¥ó
errno.h
E[0-9A-Z].*
ctype.h
(to|is)[a-z].*
locale.h
LC_[A-Z].*
math.h
<¸½ºß¤Î´Ø¿ô̾> [fl]
signal.h
(SIG|SIG_)[A-Z].*
stdlib.h
str[a-z].*
string.h
(str|mem|wcs)[a-z].*


¾åµ­¥ê¥¹¥È¤Ë¤ª¤¤¤Æ¡¢Âçʸ»ú¤Î±Ñ»ú¤Ç»Ï¤Þ¤ë̾Á°¤Ï¥Þ¥¯¥í¤Ç¡¢´ØÏ¢¤¹¤ë¥Ø¥Ã¥À¡¼¤¬¥¤¥ó¥¯¥ë¡¼¥É¤µ¤ì¤ë¤È¤­¤À¤±Í½Ì󤵤ì¤Þ¤¹¡£»Ä¤ê¤Î̾Á°¤Ï´Ø¿ô¤ò¼¨¤·¡¢Âç°èŪ¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤ä´Ø¿ô¤ò»ØÄꤹ¤ë¾ì¹ç¤Ë¤Ï»ÈÍѤǤ­¤Þ¤»¤ó¡£

°ÂÁ´¤Ë»ÈÍѤǤ­¤ë̾Á°

ANSI/ISO C ¤ÎͽÌó̾¤È¾×Æͤ·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¼¡¤Î 4 ¤Ä¤Î´Êñ¤Êµ¬Â§¤Ë½¾¤¦É¬Íפ¬¤¢¤ê¤Þ¤¹¡£

¤Û¤È¤ó¤É¤Î¼ÂÁõ¤Ï¥Ç¥Õ¥©¥ë¥È¤Çɸ½à¥Ø¥Ã¥À¡¼¤Ë̾Á°¤òÄɲ䷤Ƥ¤¤ë¤¿¤á¡¢¤³¤ì¤é¤Îµ¬Â§¤Ï°ìÈÌŪ¤Ê¥¬¥¤¥É¥é¥¤¥ó¤Ë²á¤®¤Þ¤»¤ó¡£

¹ñºÝ²½

¡ÖÊ£¿ô¥Ð¥¤¥Èʸ»ú¤È¥ï¥¤¥Éʸ»ú¡×¤ÎÀá¤Ç¤Ï¡¢É¸½à¥é¥¤¥Ö¥é¥ê¤Î¹ñºÝ²½¤ò¾Ò²ð¤·¤Þ¤·¤¿¡£¤³¤ÎÀá¤Ç¤Ï¡¢¹ñºÝ²½¤Î±Æ¶Á¤ò¼õ¤±¤ë¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¡¢¤³¤ì¤é¤Îµ¡Ç½¤òÍøÍѤ¹¤ë¤Ë¤Ï¤É¤Î¤è¤¦¤Ë¥×¥í¥°¥é¥à¤ò½ñ¤±¤Ð¤¤¤¤¤«¤Î¥Ò¥ó¥È¤òÄ󶡤·¤Þ¤¹¡£

¥í¥±¡¼¥ë

C ¥×¥í¥°¥é¥à¤Ï¾ï¤Ë¡¢¸½ºß¤Î¥í¥±¡¼¥ë (¹ñ¡¢Ê¸²½¡¢¤ª¤è¤Ó¸À¸ì¤ËŬÀڤʵ¬Ìó¤òµ­½Ò¤·¤¿¾ðÊó¤Î½¸¤Þ¤ê) ¤ò»ý¤Ã¤Æ¤¤¤Þ¤¹¡£¥í¥±¡¼¥ë¤Ïʸ»úÎó¤Î̾Á°¤ò»ý¤Ã¤Æ¤¤¤Þ¤¹¡£É¸½à²½¤µ¤ì¤¿¥í¥±¡¼¥ë̾¤Ï¡¢"C" ¤È "" ¤Î 2 ¤Ä¤À¤±¤Ç¤¹¡£¤É¤Î¥×¥í¥°¥é¥à¤â "C" ¥í¥±¡¼¥ë¤«¤é»Ï¤Þ¤ê¤Þ¤¹¡£¤Ä¤Þ¤ê¡¢¤¹¤Ù¤Æ¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ï½¾Íè¤É¤ª¤ê¤ËÆ°ºî¤·¤Þ¤¹¡£"" ¥í¥±¡¼¥ë¤Ï¡¢³Æ½èÍý·Ï¤¬¥×¥í¥°¥é¥à¤Î¸Æ¤Ó½Ð¤·¤ËºÇŬ¤Ç¤¢¤ë¤È¿ä¬¤¹¤ëµ¬Ì󥻥åȤǤ¹¡£"C" ¤È "" ¤ÎÆ°ºî¤ÏƱ¤¸¤Ë¤Ê¤ë¤³¤È¤â¤¢¤ê¤Þ¤¹¡£Â¾¤Î¥í¥±¡¼¥ë¤Ï³Æ½èÍý·Ï¤Ë¤è¤Ã¤ÆÄ󶡤µ¤ì¤Þ¤¹¡£

¼ÂÍÑÀ­¤ÈÊص¹¾å¤ÎÌÜŪ¤Ë¤è¤ê¡¢¥í¥±¡¼¥ë¤Ï¥«¥Æ¥´¥ê¤ËʬÎव¤ì¤Þ¤¹¡£¥×¥í¥°¥é¥à¤Ï¡¢¥í¥±¡¼¥ëÁ´ÂΤòÊѹ¹¤¹¤ë¤³¤È¤â¡¢1 ¤Ä¤Þ¤¿¤ÏÊ£¿ô¤Î¥«¥Æ¥´¥ê¤òÊѹ¹¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£°ìÈÌŪ¤Ë³Æ¥«¥Æ¥´¥ê¤Ï¡¢Â¾¤Î¥«¥Æ¥´¥ê¤¬±Æ¶Á¤òÍ¿¤¨¤ë´Ø¿ô¤È¤Ï´Ø·¸¤Ê¤¯¡¢Ê£¿ô¤Î´Ø¿ô¤Ë±Æ¶Á¤òÍ¿¤¨¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢°ì»þŪ¤Ë 1 ¤Ä¤Î¥«¥Æ¥´¥ê¤òÊѹ¹¤¹¤ë¤³¤È¤Ë¤â°ÕÌ£¤¬¤¢¤ê¤Þ¤¹¡£

setlocale() ´Ø¿ô

setlocale() ´Ø¿ô¤Ï¡¢¥×¥í¥°¥é¥à¤Î¥í¥±¡¼¥ë¤È¤Î¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Ç¤¹¡£°ìÈÌŪ¤Ë¡¢¹ñ¤Îµ¬Ìó¤ò¸Æ¤Ó½Ð¤·¤Æ»ÈÍѤ¹¤ë¥×¥í¥°¥é¥à¤Ï¡¢¥×¥í¥°¥é¥à¤Î¼Â¹Ô¥Ñ¥¹¤ÎÁ°¤Î¤Û¤¦¤Ç¡¢¼¡¤Î¤è¤¦¤Ê¸Æ¤Ó½Ð¤·¤ò¹Ô¤ï¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£

#include <locale.h>
/*...*/
setlocale(LC_ALL, "");


LC_ALL ¤Ï 1 ¤Ä¤Î¥«¥Æ¥´¥ê¤Ç¤Ï¤Ê¤¯¡¢¥í¥±¡¼¥ëÁ´ÂΤò»ØÄꤹ¤ë¥Þ¥¯¥í¤Ç¤¢¤ë¤¿¤á¡¢¤³¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤Æ¡¢¥×¥í¥°¥é¥à¤Î¸½ºß¤Î¥í¥±¡¼¥ë¤¬Å¬ÀÚ¤Ê¥í¡¼¥«¥ë¥Ð¡¼¥¸¥ç¥ó¤ËÊѹ¹¤µ¤ì¤Þ¤¹¡£¼¡¤Ë¡¢É¸½àŪ¤Ê¥«¥Æ¥´¥ê¤ò¼¨¤·¤Þ¤¹¡£

LC_COLLATE
¥½¡¼¥È¾ðÊó
LC_CTYPE
ʸ»úʬÎà¾ðÊó
LC_MONETARY
Ä̲ߤνÐÎϾðÊó
LC_NUMERIC
¿ôÃͤνÐÎϾðÊó
LC_TIME
ÆüÉդȻþ¹ï¤Î½ÐÎϾðÊó


¾åµ­¤ÎǤ°Õ¤Î¥Þ¥¯¥í¤ò setlocale() ¤Ø¤ÎºÇ½é¤Î°ú¿ô¤È¤·¤ÆÅϤ¹¤³¤È¤Ë¤è¤Ã¤Æ¡¢¤½¤Î¥«¥Æ¥´¥ê¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£

setlocale() ´Ø¿ô¤Ï¡¢ÆÃÄê¤Î¥«¥Æ¥´¥ê (¤Þ¤¿¤Ï¡¢LC_ALL) ¤ËÂФ¹¤ë¸½ºß¤Î¥í¥±¡¼¥ë¤Î̾Á°¤òÊÖ¤·¤Þ¤¹¡£2 ÈÖÌܤΰú¿ô¤¬¥Ì¥ë¥Ý¥¤¥ó¥¿¤Î¾ì¹ç¤Ï¡¢¾È²ñÀìÍѤȤ·¤Æµ¡Ç½¤·¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¼¡¤Î¤è¤¦¤Ê¥³¡¼¥É¤ò»ÈÍѤ¹¤ë¤È¡¢À©¸Â¤µ¤ì¤¿´ü´Ö¤À¤±¥í¥±¡¼¥ë (¤Þ¤¿¤Ï¡¢¤½¤Î°ìÉô) ¤òÊѹ¹¤Ç¤­¤Þ¤¹¡£

#include <locale.h>
/*...*/
char *oloc;
/*...*/
oloc = setlocale(LC_<¥«¥Æ¥´¥ê̾>, NULL);
if (setlocale(LC_<¥«¥Æ¥´¥ê̾>, "new") != 0)
{
        /* use temporarily changed locale */
    (void)setlocale(LC_<¥«¥Æ¥´¥ê̾>, oloc);
}


¤Û¤È¤ó¤É¤Î¥×¥í¥°¥é¥à¤Ç¤Ï¤³¤Îµ¡Ç½¤ÏɬÍפ¢¤ê¤Þ¤»¤ó¡£

Êѹ¹¤µ¤ì¤¿´Ø¿ô

Êѹ¹¤¬Å¬ÀڤDzÄǽ¤Ç¤¢¤ë¾ì¹ç¡¢´û¸¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ï¥í¥±¡¼¥ë¤Ë°Í¸¤¹¤ëÆ°ºî¤ò´Þ¤à¤è¤¦¤Ë³ÈÄ¥¤µ¤ì¤Þ¤·¤¿¡£¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢¼¡¤Î 2 ¤Ä¤Î¥°¥ë¡¼¥×¤ËʬÎà¤Ç¤­¤Þ¤¹¡£

¤¹¤Ù¤Æ¤Î ctype.h ½Ò¸ì´Ø¿ô (isdigit() ¤È isxdigit() ¤ò½ü¤¯) ¤Ï¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤Î LC_CTYPE ¥«¥Æ¥´¥ê¤¬ "C" °Ê³°¤Î¾ì¹ç¤Ë¡¢ÄɲäÎʸ»ú¤ËÂФ·¤Æ¥¼¥í¤Ç¤Ê¤¤ (¿¿¤Î) ÃͤòÊÖ¤¹¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥¹¥Ú¥¤¥ó¸ì¥í¥±¡¼¥ë¤Ç¤Ï isalpha (`') ¤Ï¿¿¤Ë¤Ê¤ê¤Þ¤¹¡£Æ±Íͤˡ¢Ê¸»úÊÑ´¹´Ø¿ô tolower() ¤È toupper() ¤Ï¡¢isalpha() ´Ø¿ô¤Ç¼±Ê̤µ¤ì¤ëÆÃÊ̤ʱѻú¤òŬÀڤ˽èÍý¤Ç¤­¤Þ¤¹¡£ctype.h ´Ø¿ô¤Ï¡¢¤Û¤È¤ó¤É¤Î¾ì¹ç¡¢Ê¸»ú°ú¿ô¤Ë¤è¤ëº÷°úÉÕ¤­¥Æ¡¼¥Ö¥ë¸¡º÷¤ò»ÈÍѤ·¤Æ¼ÂÁõ¤µ¤ì¤ë¥Þ¥¯¥í¤Ç¤¹¡£¤³¤ì¤é¤Î´Ø¿ô¤ÎÆ°ºî¤òÊѹ¹¤¹¤ë¤Ë¤Ï¡¢¥Æ¡¼¥Ö¥ë¤ò¿·¤·¤¤¥í¥±¡¼¥ë¤ÎÃͤ˺ÆÀßÄꤷ¤Þ¤¹¡£¤·¤¿¤¬¤Ã¤Æ¡¢¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤Ë±Æ¶Á¤Ï¤¢¤ê¤Þ¤»¤ó¡£

½ÐÎϲÄǽ¤ÊÉâÆ°¾®¿ôÅÀÃͤò½ñ¤­¹þ¤ó¤À¤ê²ò¼á¤·¤¿¤ê¤¹¤ë¾åµ­¤Î´Ø¿ô¤Ï¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤Î LC_NUMERIC ¥«¥Æ¥´¥ê¤¬ "C" °Ê³°¤Î¾ì¹ç¤Ë¡¢¥Ô¥ê¥ª¥É (.) °Ê³°¤Î¾®¿ôÅÀʸ»ú¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÊѹ¹¤Ç¤­¤Þ¤¹¡£Àéñ°Ì¶èÀڤ귿ʸ»ú¤Ç¿ôÃͤò½ÐÎϲÄǽ¤Ê·Á¼°¤ËÊÑ´¹¤¹¤ë¤¿¤á¤Îµ¬Äê¤Ï¤¢¤ê¤Þ¤»¤ó¡£½ÐÎϺþ²Äǽ¤Ê·Á¼°¤«¤éÆâÉôŪ¤Ê·Á¼°¤ËÊÑ´¹¤¹¤ë¤È¤­¤Ë¤â¡¢¼ÂÁõ¤Ç¤Ï¡¢"C" °Ê³°¤Î¥í¥±¡¼¥ë¤Î¾ì¹ç¤Ë¡¢¤³¤Î¤è¤¦¤ÊÄɲäηÁ¼°¤ò¼õ¤±Æþ¤ì¤ë¤³¤È¤¬µö²Ä¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¾®¿ôÅÀʸ»ú¤ò»ÈÍѤ¹¤ë´Ø¿ô¤Ï¡¢printf() ¤È scanf() ¤Î¥°¥ë¡¼¥×¡¢atof()¡¢¤ª¤è¤Ó strtod() ¤Ç¤¹¡£¼ÂÁõ¤Ç¤ÎÄêµÁ¤ò³ÈÄ¥¤Ç¤­¤ë´Ø¿ô¤Ï¡¢atof()¡¢
atoi()¡¢atol()¡¢strtod()¡¢strtol()¡¢strtoul()¡¢¤ª¤è¤Ó scanf() ¤Î¥°¥ë¡¼¥×¤Ç¤¹¡£

¿·¤·¤¤´Ø¿ô

¿·¤·¤¤É¸½à´Ø¿ô¤È¤·¤Æ¡¢ÆÃÄê¤Î¥í¥±¡¼¥ë¤Ë°Í¸¤¹¤ëµ¡Ç½¤¬Äɲ䵤ì¤Þ¤·¤¿¡£¥í¥±¡¼¥ë¼«¿È¤òÀ©¸æ¤¹¤ë setlocale() °Ê³°¤Ë¤â¡¢ANSI/ISO C µ¬³Ê¤Ë¤Ï¼¡¤Î¿·¤·¤¤´Ø¿ô¤¬Æ³Æþ¤µ¤ì¤Þ¤·¤¿¡£

localeconv() ¿ôÃÍ/Ä̲ߤε¬Ìó
strcoll() 2 ¤Ä¤Îʸ»úÎó¤Î¾È¹ç½ç½ø
strxfrm() ¾È¹ç¤Î¤¿¤á¤Ëʸ»úÎó¤òÊÑ´¹¤¹¤ë
strftime() ¾È¹ç¤Î¤¿¤á¤Ëʸ»úÎó¤òÊÑ´¹¤¹¤ë


¤µ¤é¤Ë¡¢Ê£¿ô¥Ð¥¤¥È´Ø¿ô mblen()¡¢mbtowc()¡¢mbstowcs()¡¢wctomb()¡¢¤ª¤è¤Ó wcstombs() ¤¬¤¢¤ê¤Þ¤¹¡£

localeconv() ´Ø¿ô¤Ï¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤Î LC_NUMERIC ¤È LC_MONETARY ¥«¥Æ¥´¥ê¤ËŬÀڤʡ¢½ñ¼°²½¤µ¤ì¤¿¿ôÃͤª¤è¤ÓÄ̲ߤξðÊó¤ËÊØÍø¤Ê¾ðÊó¤ò´Þ¤à¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤òÊÖ¤·¤Þ¤¹¡£¤³¤Î´Ø¿ô¤Ï¡¢Æ°ºî¤¬Ê£¿ô¤Î¥«¥Æ¥´¥ê¤Ë°Í¸¤¹¤ëÍ£°ì¤Î´Ø¿ô¤Ç¤¹¡£¿ôÃͤξì¹ç¡¢¹½Â¤ÂΤϡ¢¾®¿ôÅÀʸ»ú¡¢Àéñ°Ì¶èÀÚ¤êʸ»ú¡¢¤ª¤è¤Ó¶èÀÚ¤êʸ»ú¤òÃÖ¤¯¾ì½ê¤òµ­½Ò¤·¤Þ¤¹¡£Ä̲ßÃͤò½ñ¼°²½¤¹¤ëÊýË¡¤òµ­½Ò¤¹¤ë¹½Â¤ÂΤΥá¥ó¥Ð¡¼¤Ï¡¢Â¾¤Ë¤â 15 ¸Ä¤¢¤ê¤Þ¤¹¡£

strcoll() ´Ø¿ô¤Ï¡¢strcmp() ´Ø¿ô¤È»÷¤Æ¤¤¤Þ¤¹¤¬¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤Î LC_COLLATE ¥«¥Æ¥´¥ê¤Ë½¾¤Ã¤Æ¡¢2 ¤Ä¤Îʸ»úÎó¤òÈæ³Ó¤¹¤ë¤È¤³¤í¤¬°Û¤Ê¤ê¤Þ¤¹¡£strxfrm() ´Ø¿ô¤Ï¡¢ÊÑ´¹¸å¤Î 2 ¤Ä¤Îʸ»úÎó¤ò strcmp() ¤ËÅϤ¹¤È¡¢ÊÑ´¹Á°¤Î 2 ¤Ä¤Îʸ»úÎó¤ò strcoll() ¤ËÅϤ·¤¿¾ì¹ç¤ËÊÖ¤µ¤ì¤ë½çÈ֤Ȼ÷¤¿½çÈÖ¤¬ÊÖ¤µ¤ì¤ë¤è¤¦¤Ë¡¢Ê¸»úÎó¤òÊ̤Îʸ»úÎó¤ËÊÑ´¹¤·¤Þ¤¹¡£

strftime() ´Ø¿ô¤Ï¡¢struct tm ¤ËÃͤò»ý¤Ä sprintf() ¤Ç»ÈÍѤµ¤ì¤ë½ñ¼°²½¤È»÷¤¿½ñ¼°²½¤È¡¢¤µ¤é¤Ë¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤Î LC_TIME ¥«¥Æ¥´¥ê¤Ë°Í¸¤¹¤ëÆüÉդȻþ¹ï¤Î½ñ¼°¤òÄ󶡤·¤Þ¤¹¡£¤³¤Î´Ø¿ô¤Ï¡¢UNIX System V ¥ê¥ê¡¼¥¹ 3.2 ¤Î°ìÉô¤È¤·¤Æ¥ê¥ê¡¼¥¹¤µ¤ì¤¿ ascftime() ´Ø¿ô¤Ë´ð¤Å¤¤¤Æ¤¤¤Þ¤¹¡£

¼°¤Î¥°¥ë¡¼¥×²½¤Èɾ²Á

C ¤ÎÀ߷פˤª¤¤¤Æ Dennis Ritchie ¤¬¹Ô¤Ê¤Ã¤¿ÁªÂò¤Î 1 ¤Ä¤È¤·¤Æ¡¢¼°¤ÎÃæ¤Ç¿ô³ØŪ¤Ë¸ò´¹²Äǽ¤Ç·ë¹ç²Äǽ¤Ê±é»»»Ò¤¬ÎÙÀܤ¹¤ë¾ì¹ç¡¢³ç¸Ì¤¬Â¸ºß¤¹¤ë¾ì¹ç¤Ç¤â¡¢¤½¤Î¼°¤òºÆÇÛÃÖ¤¹¤ë¸¢Íø¤ò¥³¥ó¥Ñ¥¤¥é¤ËÍ¿¤¨¤Þ¤·¤¿¡£¤³¤Î¤³¤È¤Ï¡¢Kernighan ¤È Ritchie Ãø¤Î¡Ø¥×¥í¥°¥é¥ß¥ó¥°¸À¸ì C¡Ù¤ÎÉÕÏ¿¤ËÌÀ¼¨Åª¤Ëµ­ºÜ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤·¤«¤·¡¢ANSI/ISO C ¤Ï¡¢¤³¤Î¸¢Íø¤ò¥³¥ó¥Ñ¥¤¥é¤ËÍ¿¤¨¤Þ¤»¤ó¤Ç¤·¤¿¡£

¤³¤ÎÀá¤Ç¤Ï¡¢¾åµ­ 2 ¤Ä¤Î C ¤ÎÄêµÁ´Ö¤Î°ã¤¤¤òÀâÌÀ¤·¤Þ¤¹¡£¤Þ¤¿¡¢¼¡¤Î¥³¡¼¥É¤Ë¤ª¤±¤ë¼°Ê¸¤ò¹Í¤¨¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢¼°¤ÎÉûºîÍÑ¡¢¥°¥ë¡¼¥×²½¡¢¤ª¤è¤Óɾ²Á¤Î´Ö¤Î¶èÊ̤òÌÀ¤é¤«¤Ë¤·¤Þ¤¹¡£

int i, *p, f(void), g(void);
/*...*/
i = *++p + f() + g();


ÄêµÁ

¼°¤ÎÉûºîÍѤȤϡ¢¥á¥â¥ê¡¼¤Ø¤ÎÊѹ¹¤È¡¢volatile ½¤¾þ¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥¢¥¯¥»¥¹¤Î¤³¤È¤Ç¤¹¡£¾åµ­¼°¤ÎÉûºîÍѤȤϡ¢i ¤È p ¤Î¹¹¿·¤È¡¢´Ø¿ô f() ¤È g() Æâ¤Ë´Þ¤Þ¤ì¤ëǤ°Õ¤ÎÉûºîÍѤǤ¹¡£

¼°¤Î¥°¥ë¡¼¥×²½¤È¤Ï¡¢Ãͤò¾¤ÎÃͤä±é»»»Ò¤È·ë¹ç¤µ¤»¤ëÊýË¡¤Ç¤¹¡£¾åµ­¤Î¼°¤Î¥°¥ë¡¼¥×²½¤Ï¡¢¼ç¤Ë²Ã»»¤ò¼Â¹Ô¤¹¤ë½çÈ֤Ǥ¹¡£

¼°¤Îɾ²Á¤Ë¤Ï¡¢¤½¤Î·ë²Ì¤ÎÃͤòÀ¸À®¤¹¤ë¤¿¤á¤ËɬÍפʤ¹¤Ù¤Æ¤¬´Þ¤Þ¤ì¤Þ¤¹¡£¼°¤òɾ²Á¤¹¤ë¤¿¤á¤Ë¤Ï¡¢»ØÄꤷ¤¿¤¹¤Ù¤Æ¤ÎÉûºîÍѤ¬°ÊÁ°¤Î¥·¡¼¥±¥ó¥¹¥Ý¥¤¥ó¥È¤«¤é¼¡¤Î¥·¡¼¥±¥ó¥¹¥Ý¥¤¥ó¥È¤Þ¤Ç¤Î´Ö¤ÇȯÀ¸¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢»ØÄꤷ¤¿±é»»¤¬ÆÃÄê¤Î¥°¥ë¡¼¥×²½¤Ç¼Â¹Ô¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¾åµ­¤Î¼°¤Î¾ì¹ç¡¢i ¤È p ¤Î¹¹¿·¤Ï¡¢°ÊÁ°¤Îʸ¤«¤é¤³¤Î¼°Ê¸¤Î ; ¤Þ¤Ç¤Î´Ö¤ËȯÀ¸¤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£´Ø¿ô¤Ø¤Î¸Æ¤Ó½Ð¤·¤Ï¡¢°ÊÁ°¤Îʸ¤«¤é¤½¤ÎÌá¤êÃͤ¬»ÈÍѤµ¤ì¤ë¤Þ¤Ç¤Î´Ö¤Ë¡¢Ç¤°Õ¤Î½çÈÖ¤ÇȯÀ¸¤Ç¤­¤Þ¤¹¡£Æäˡ¢¥á¥â¥ê¡¼¤ò¹¹¿·¤¹¤ë±é»»»Ò¤Ë¤Ï¡¢±é»»¤ÎÃͤ¬»ÈÍѤµ¤ì¤ëÁ°¤Ë¿·¤·¤¤ÃͤòÂåÆþ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤È¤¤¤¦À©Ìó¤Ï¤¢¤ê¤Þ¤»¤ó¡£

K&R C ¤ÎºÆÇÛÃ֥饤¥»¥ó¥¹

¾åµ­¤Î¼°¤Ç¤Ï²Ã»»¤¬¿ô³ØŪ¤Ë¸ò´¹²Äǽ¤Ç¡¢¤Þ¤¿·ë¹ç²Äǽ¤Ç¤¢¤ë¤¿¤á¡¢K&R C ¤ÎºÆÇÛÃ֤θ¢Íø¤¬¾åµ­¼°¤ËŬÍѤµ¤ì¤Þ¤¹¡£Ä̾ï¤Î³ç¸Ì¤È¼ÂºÝ¤Î¼°¤Î¥°¥ë¡¼¥×²½¤ò¶èÊ̤¹¤ë¤¿¤á¤Ë¡¢º¸±¦¤ÎÃæ³ç¸Ì¤Ç¥°¥ë¡¼¥×²½¤ò¼¨¤·¤Þ¤¹¡£¤³¤Î¼°¤Î¾ì¹ç¡¢¼¡¤Î 3 ¤Ä¤Î¥°¥ë¡¼¥×²½¤¬¹Í¤¨¤é¤ì¤Þ¤¹¡£

i = { {*++p + f()} + g() };
i = { *++p + {f() + g()} };
i = { {*++p + g()} + f() };


¾åµ­¤¹¤Ù¤Æ¤Î¥°¥ë¡¼¥×²½¤Ï¡¢K&R C ¤Îµ¬Â§¤Ç¤¢¤ì¤ÐÍ­¸ú¤Ç¤¹¡£¤µ¤é¤Ë¡¢¤¿¤È¤¨¤Ð¡¢¼¡¤Î¤è¤¦¤Ë¼°¤ò½ñ¤­´¹¤¨¤¿¾ì¹ç¤Ç¤â¡¢¾åµ­¤¹¤Ù¤Æ¤Î¥°¥ë¡¼¥×²½¤ÏÍ­¸ú¤Ç¤¹¡£

i = *++p + (f() + g());
i = (g() + *++p) + f();


¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤Ë¤è¤Ã¤ÆÎã³°¤¬È¯À¸¤¹¤ë¤«¡¢¤¢¤ë¤¤¤Ï¡¢¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤Ç²Ã»»¤È¸º»»¤¬µÕ¤Ë¤Ê¤é¤Ê¤¤¥¢¡¼¥­¥Æ¥¯¥Á¥ã¾å¤Ç¤³¤Î¼°¤¬É¾²Á¤µ¤ì¤ë¾ì¹ç¡¢²Ã»»¤Î 1 ¤Ä¤¬¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤·¤¿¤È¤­¡¢¾åµ­ 3 ¤Ä¤Î¥°¥ë¡¼¥×²½¤ÎÆ°ºî¤Ï°Û¤Ê¤ê¤Þ¤¹¡£

¤³¤Î¤è¤¦¤Ê¥¢¡¼¥­¥Æ¥¯¥Á¥ã¾å¤Ç¤Ï¡¢K&R C ¤Ç¤Ï¡¢¼°¤òʬ³ä¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¶¯À©Åª¤Ë¥°¥ë¡¼¥×²½¤¹¤ë¤·¤«ÊýË¡¤¬¤¢¤ê¤Þ¤»¤ó¡£¼¡¤Ë¡¢¾åµ­ 3 ¤Ä¤Î¥°¥ë¡¼¥×²½¤ò¶¯À©Åª¤Ë¹Ô¤¦¤¿¤á¤Ë¼°¤òʬ³ä¤·¤¿Îã¤ò¼¨¤·¤Þ¤¹¡£

i = *++p; i += f(); i += g();
i = f(); i += g(); i += *++p;
i = *++p; i += g(); i += f();


ANSI/ISO C ¤Îµ¬Â§

ANSI/ISO C ¤Ç¤Ï¡¢¿ô³ØŪ¤Ë¸ò´¹²Äǽ¤Ç·ë¹ç²Äǽ¤Ç¤¢¤ë¤¬¡¢ÂоݤȤʤ륢¡¼¥­¥Æ¥¯¥Á¥ã¾å¤Ç¤Ï¼ÂºÝ¤Ë¤½¤¦¤Ç¤Ï¤Ê¤¤±é»»¤òºÆÇÛÃÖ¤¹¤ë¤³¤È¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£¤·¤¿¤¬¤Ã¤Æ¡¢ANSI/ISO C ¤Îʸˡ¤ÎÍ¥ÀèÅ٤ȷë¹çµ¬Â§¤Ç¤Ï¡¢¤¹¤Ù¤Æ¤Î¼°¤Î¥°¥ë¡¼¥×²½¤¬´°Á´¤Ëµ­½Ò¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤Ä¤Þ¤ê¡¢¤¹¤Ù¤Æ¤Î¼°¤Ï¡¢¹½Ê¸²òÀϤµ¤ì¤ë¤È¤ª¤ê¤Ë¥°¥ë¡¼¥×²½¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¾åµ­¤Î¼°¤Ï¡¢¼¡¤ÎÊýË¡¤Ç¥°¥ë¡¼¥×²½¤µ¤ì¤Þ¤¹¡£

i = { {*++p + f()} + g() };


¤³¤Î¥³¡¼¥É¤Ç¤â¤Ê¤ª¡Öf() ¤¬ g() ¤è¤ê¤âÁ°¤Ë¸Æ¤Ó½Ð¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡×¡¢¤¢¤ë¤¤¤Ï¡¢¡Ög() ¤¬¸Æ¤Ó½Ð¤µ¤ì¤ë¤è¤ê¤âÁ°¤Ë p ¤¬Áýʬ¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡×¤È¤¤¤¦¤³¤È¤Ï¤¢¤ê¤Þ¤»¤ó¡£

ANSI/ISO C ¤Ç¤Ï¡¢Í½ÁÛ³°¤Î¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤¬È¯À¸¤·¤Ê¤¤¤è¤¦¤Ë¼°¤òʬ³ä¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£

³ç¸Ì

ANSI/ISO C ¤Ç¤Ï¡¢ÉÔ½¼Ê¬¤ÊÍý²ò¤ÈÉÔÀµ³Î¤Êɽ¸½¤Î¤¿¤á¤Ë¡¢³ç¸Ì¤Î¿®ÍêÀ­¤È³ç¸Ì¤Ë½¾¤Ã¤¿É¾²Á¤Ë¤Ä¤¤¤Æ¡¢´Ö°ã¤Ã¤Æµ­½Ò¤µ¤ì¤ë¤³¤È¤¬¤·¤Ð¤·¤Ð¤¢¤ê¤Þ¤¹¡£

ANSI/ISO C ¤Î¼°¤Ï¹½Ê¸²òÀϤǻØÄꤵ¤ì¤ë¥°¥ë¡¼¥×²½¤ò»ý¤Ä¤¿¤á¡¢³ç¸Ì¤Ï¡¢¤É¤Î¤è¤¦¤Ë¼°¤¬¹½Ê¸²òÀϤµ¤ì¤ë¤«¤òÀ©¸æ¤¹¤ëÊýË¡¤È¤·¤Æ¤À¤±µ¡Ç½¤·¤Þ¤¹¡£¤Ä¤Þ¤ê¡¢¼°¤Î¼«Á³¤ÊÍ¥ÀèÅ٤ȷë¹çµ¬Â§¤¬³ç¸Ì¤È¤Þ¤Ã¤¿¤¯Æ±¤¸½ÅÍפµ¤ò»ý¤Á¤Þ¤¹¡£

¾åµ­¤Î¼°¤Ï¡¢¼¡¤Î¤è¤¦¤Ë½ñ¤¯¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

i = (((*(++p)) + f()) + g());


¥°¥ë¡¼¥×²½¤Èɾ²Á¤ËÍ¿¤¨¤ë±Æ¶Á¤Ï¡¢³ç¸Ì¤ò»ÈÍѤ·¤Ê¤¤¾ì¹ç¤ÈƱ¤¸¤Ç¤¹¡£

as if µ¬Â§

K&R C ¤ÎºÆÇÛÃÖµ¬Â§¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«¤ÎÍýͳ¤¬¤¢¤ê¤Þ¤·¤¿¡£

ANSI/ISO C °Ñ°÷²ñ¤Ï¡¢µ­½Ò¤µ¤ì¤ëÂоݥ¢¡¼¥­¥Æ¥¯¥Á¥ã¤ËŬÍѤµ¤ì¤ë¤È¤­¤Ë¡¢ºÆÇÛÃÖµ¬Â§¤Ï as if µ¬Â§¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤Ë¤Ê¤ë¤â¤Î¤Ç¤¢¤ë¤È¡¢ºÇ½ªÅª¤Ë³Î¿®¤·¤Þ¤·¤¿¡£ANSI/ISO C ¤Î as if µ¬Â§¤Ï¡¢Í­¸ú¤Ê C ¥×¥í¥°¥é¥à¤ÎÆ°ºî¤òÊѹ¹¤·¤Ê¤¤¸Â¤ê¡¢¼ÂÁõ¤¬É¬Íפ˱þ¤¸¤ÆÃê¾Ý¥Þ¥·¥óµ­½Ò¤«¤éÎ¥¤ì¤ë¤³¤È¤ò°ìÈÌŪ¤Ëµö²Ä¤·¤Æ¤¤¤Þ¤¹¡£

¤·¤¿¤¬¤Ã¤Æ¡¢¤¹¤Ù¤Æ¤Î¥Ó¥Ã¥Èñ°Ì¤Î 2 ¹à±é»»»Ò (¥·¥Õ¥È¤ò½ü¤¯) ¤ÏǤ°Õ¤Î¥Þ¥·¥ó¤ÇºÆÇÛÃ֤Ǥ­¤Þ¤¹¡£¤³¤ì¤Ï¡¢¤³¤Î¤è¤¦¤ÊºÆ¥°¥ë¡¼¥×²½¤ò³Îǧ¤Ç¤­¤ëÊýË¡¤¬¤Ê¤¤¤¿¤á¤Ç¤¹¡£2 ¤ÎÊä¿ô¤ò»ÈÍѤ¹¤ë¥Þ¥·¥ó¤Ç¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤¬È¯À¸¤·¤Ê¤¤¾ì¹ç¤Ï¡¢¤¤¤¯¤Ä¤«¤ÎÍýͳ¤Î¤¿¤á¡¢¾è»»¤Þ¤¿¤Ï²Ã»»¤ò´Þ¤àÀ°¿ô¼°¤ÏºÆÇÛÃ֤Ǥ­¤Þ¤¹¡£

¤·¤¿¤¬¤Ã¤Æ¡¢C ¤Ë¤ª¤±¤ë¤³¤ÎÊѹ¹¤Ï¡¢¤Û¤È¤ó¤É¤Î C ¥×¥í¥°¥é¥Þ¤Ë¤Ï½ÅÍפʱƶÁ¤òÍ¿¤¨¤Þ¤»¤ó¡£

ÉÔ´°Á´¤Ê·¿

(C ¤ÎÅö½é¤«¤éÆâºß¤·)¡¢C ¤Î´ðËÜŪ¤ÊÉôʬ¤Ç¤¢¤ë¤¬¤Þ¤À¿¿²Á¤òǧ¤á¤é¤ì¤Æ¤¤¤Ê¤¤Éôʬ¤òÀµ¼°¤Ê¤â¤Î¤È¤¹¤ë¤¿¤á¤Ë¡¢ANSI/ISO C µ¬³Ê¤Ï¡ÖÉÔ´°Á´¤Ê·¿¡×¤òƳÆþ¤·¤Þ¤·¤¿¡£¤³¤ÎÀá¤Ç¤Ï¡¢ÉÔ´°Á´¤Ê·¿¤¬¤É¤³¤Çµö²Ä¤µ¤ì¤ë¤«¤È¡¢¤Ê¤¼ÊØÍø¤Ç¤¢¤ë¤«¤òÀâÌÀ¤·¤Þ¤¹¡£

·¿

ANSI/ISO ¤Ï C ¤Î·¿¤ò¡¢´Ø¿ô¡¢¥ª¥Ö¥¸¥§¥¯¥È¡¢¤ª¤è¤ÓÉÔ´°Á´¤Î 3 ¤Ä¤Ë¶èʬ¤·¤Þ¤·¤¿¡£´Ø¿ô·¿¤ÎÄêµÁ¤ÏÌÀÇò¤Ç¤¹¡£¥ª¥Ö¥¸¥§¥¯¥È·¿¤Ï¡¢¥µ¥¤¥º¤¬ÉÔÌÀ¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤ò½ü¤¯¡¢¤½¤Î¾¤¹¤Ù¤Æ¤Î¤â¤Î¤ò¼¨¤·¤Þ¤¹¡£ANSI/ISO C µ¬³Ê¤Ï¡¢ÌÀ¼¨¤µ¤ì¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¥µ¥¤¥º¤¬´ûÃΤǤʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤¤³¤È¤ò»ØÄꤹ¤ë¤¿¤á¤Ë¡¢¡Ö¥ª¥Ö¥¸¥§¥¯¥È·¿¡×¤ò»ÈÍѤ·¤Þ¤¹¡£¤·¤«¤·¡¢void °Ê³°¤ÎÉÔ´°Á´¤Ê·¿¤â¥ª¥Ö¥¸¥§¥¯¥È¤ò»Ø¤¹¤³¤È¤Ï½½Ê¬¤ËÍý²ò¤·¤Æ¤¯¤À¤µ¤¤¡£

ÉÔ´°Á´¤Ê·¿¤Ë¤Ï¡¢void¡¢ÉÔÆÃÄêŤÎÇÛÎ󡢤ª¤è¤ÓÉÔÆÃÄêÆâÍƤι½Â¤ÂΤȶ¦ÍÑÂΤΠ3 ¤Ä¤Î¼ïÎष¤«¤¢¤ê¤Þ¤»¤ó¡£·¿ void ¤Ï¡¢´°À®¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤ÉÔ´°Á´¤Ê·¿¤Ç¤¢¤ë¤È¤¤¤¦ÅÀ¤Ç¾¤Î 2 ¤Ä¤È¤Ï°Û¤Ê¤ê¤Þ¤¹¡£¤½¤·¤Æ¡¢ÆÃÊ̤ʴؿô¤ÎÌá¤ê·¿¤È¥Ñ¥é¥á¡¼¥¿·¿¤È¤·¤Æµ¡Ç½¤·¤Þ¤¹¡£

ÉÔ´°Á´¤Ê·¿¤ò´°Á´¤Ë¤¹¤ë

ÉÔ´°Á´¤ÊÇÛÎ󷿤ò´°Á´¤Ê¤â¤Î¤Ë¤¹¤ë¤Ë¤Ï¡¢Æ±¤¸¥ª¥Ö¥¸¥§¥¯¥È¤ò¼¨¤¹Æ±¤¸¥¹¥³¡¼¥×Æâ¤Ë¤¢¤ë¸å³¤ÎÀë¸À¤Ç¡¢ÇÛÎó¤Î¥µ¥¤¥º¤ò»ØÄꤷ¤Þ¤¹¡£Æ±¤¸Àë¸À¤Ç¥µ¥¤¥º¤¬ÉÔÌÀ¤ÊÇÛÎó (ÉÔÆÃÄêŤÎÇÛÎó) ¤¬Àë¸À¤ª¤è¤Ó½é´ü²½¤µ¤ì¤ë¤È¤­¡¢¤½¤ÎÇÛÎó¤Ï¡¢Àë¸À¤Î½ª¤ï¤ê¤«¤é½é´ü²½¤Î½ª¤ï¤ê¤Þ¤Ç¤Î´Ö¤À¤±¡¢ÉÔ´°Á´¤Ê·¿¤Ë¤Ê¤ê¤Þ¤¹¡£

ÉÔ´°Á´¤Ê¹½Â¤Âη¿¤Þ¤¿¤Ï¶¦ÍÑÂη¿¤ò´°À®¤µ¤»¤ë¤Ë¤Ï¡¢Æ±¤¸¥¿¥°¤ÎƱ¤¸¥¹¥³¡¼¥×Æâ¤Ë¤¢¤ë¸å³¤ÎÀë¸À¤Ç¡¢¹½Â¤Âη¿¤Þ¤¿¤Ï¶¦ÍÑÂη¿¤ÎÆâÍƤò»ØÄꤷ¤Þ¤¹¡£

Àë¸À

ÉÔ´°Á´¤Ê·¿¤ò»ÈÍѤǤ­¤ëÀë¸À¤â¤¢¤ê¤Þ¤¹¤¬¡¢´°Á´¤Ê¥ª¥Ö¥¸¥§¥¯¥È·¿¤¬É¬ÍפÊÀë¸À¤â¤¢¤ê¤Þ¤¹¡£¥ª¥Ö¥¸¥§¥¯¥È·¿¤òɬÍפȤ¹¤ëÀë¸À¤Ï¡¢ÇÛÎóÍ×ÁÇ¡¢¹½Â¤ÂΤޤ¿¤Ï¶¦ÍÑÂΤΥá¥ó¥Ð¡¼¡¢¤ª¤è¤Ó´Ø¿ô¤Ë¶É½êŪ¤Ê¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¹¡£Â¾¤Î¤¹¤Ù¤Æ¤ÎÀë¸À¤Ï¡¢ÉÔ´°Á´¤Ê·¿¤òµö²Ä¤·¤Þ¤¹¡£Æäˡ¢¼¡¤Î¹½Â¤¤¬µö²Ä¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

´Ø¿ô¤ÎÌá¤ê·¿¤È¥Ñ¥é¥á¡¼¥¿·¿¤ÏÆÃÊ̤Ǥ¹¡£¤³¤Î¤è¤¦¤ÊÊýË¡¤Ç»ÈÍѤµ¤ì¤ëÉÔ´°Á´¤Ê·¿ (void ¤ò½ü¤¯) ¤Ï¡¢´Ø¿ô¤¬Àë¸À¤Þ¤¿¤Ï¸Æ¤Ó½Ð¤µ¤ì¤ë¤È¤­¤Þ¤Ç¤Ë´°Á´¤Ë¤Ê¤é¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£void ¤ÎÌá¤ê·¿¤Ï¡¢ÃͤòÊÖ¤µ¤Ê¤¤´Ø¿ô¤ò»ØÄꤷ¤Þ¤¹¡£¤Þ¤¿¡¢void ¤Îñ°ì¤Î¥Ñ¥é¥á¡¼¥¿·¿¤Ï¡¢°ú¿ô¤ò¼õ¤±Æþ¤ì¤Ê¤¤´Ø¿ô¤ò»ØÄꤷ¤Þ¤¹¡£

ÇÛÎó¤È´Ø¿ô¤Î¥Ñ¥é¥á¡¼¥¿·¿¤Ï¥Ý¥¤¥ó¥¿·¿¤Ë½ñ¤­´¹¤¨¤é¤ì¤ë¤¿¤á¡¢ÇÛÎó¤Î¥Ñ¥é¥á¡¼¥¿·¿¤Ï³°¸«¾åÉÔ´°Á´¤Ç¤¹¤¬¡¢¼ÂºÝ¤Ë¤ÏÉÔ´°Á´¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£Åµ·¿Åª¤Ê main ¤Î argv (¤Ä¤Þ¤ê¡¢char *argv[]) ¤ÎÀë¸À¤Ï¡¢ÉÔÆÃÄêŤÎʸ»ú¥Ý¥¤¥ó¥¿¤ÎÇÛÎó¤È¤·¤Æ¡¢Ê¸»ú¥Ý¥¤¥ó¥¿¤Ø¤Î¥Ý¥¤¥ó¥¿¤È¤·¤Æ½ñ¤­´¹¤¨¤é¤ì¤Þ¤¹¡£

¼°

¤Û¤È¤ó¤É¤Î¼°±é»»»Ò¤Ç¤Ï´°Á´¤Ê¥ª¥Ö¥¸¥§¥¯¥È·¿¤¬É¬ÍפǤ¹¤¬¡¢Îã³°¤¬ 3 ¤Ä¤¢¤ê¤Þ¤¹¡£Ã±¹à & ±é»»»Ò¡¢¥³¥ó¥Þ±é»»»Ò¤ÎºÇ½é¤Î¥ª¥Ú¥é¥ó¥É¡¢¤ª¤è¤Ó ?: ±é»»»Ò¤Î 2 ÈÖÌÜ¤È 3 ÈÖÌܤΥª¥Ú¥é¥ó¥É¤Ç¤¹¡£¥Ý¥¤¥ó¥¿¤Î¥ª¥Ú¥é¥ó¥É¤ò¼õ¤±Æþ¤ì¤ë¤Û¤È¤ó¤É¤Î±é»»»Ò¤Ï¡¢¥Ý¥¤¥ó¥¿±é»»¤¬Í׵ᤵ¤ì¤Ê¤¤¸Â¤ê¡¢ÉÔ´°Á´¤Ê·¿¤Ø¤Î¥Ý¥¤¥ó¥¿¤âµö²Ä¤·¤Þ¤¹¡£¤³¤ÎÃæ¤Ë¤Ï¡¢Ã±¹à * ±é»»»Ò¤â´Þ¤Þ¤ì¤Þ¤¹¡£¤¿¤È¤¨¤Ð¡¢¼¡¤ÎÎã¤ò¸«¤Æ¤¯¤À¤µ¤¤¡£

void *p


&*p ¤Ï¡¢¤³¤ÎÎã¤ò»ÈÍѤ¹¤ëÍ­¸ú¤Ê¼°¤Î°ìÉô¤Ç¤¹¡£

ÀµÅöÀ­

¤Ê¤¼ÉÔ´°Á´¤Ê·¿¤¬É¬ÍפʤΤǤ·¤ç¤¦¤«¡£void ¤ò½ü¤¤¤Æ¡¢C ¤Ç¤Ï¾¤ÎÊýË¡¤Ç°·¤¨¤Ê¤¤ÉÔ´°Á´¤Ê·¿¤ÎÍ£°ì¤Îµ¡Ç½¤Ï¡¢¹½Â¤ÂΤȶ¦ÍÑÂΤÎÁ°Êý»²¾È¤Ç¤¹¡£¤¿¤È¤¨¤Ð¡¢2 ¤Ä¤Î¹½Â¤ÂΤ¬¤ª¸ß¤¤¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤òɬÍפȤ¹¤ë¾ì¹ç¡¢¤³¤ì¤ò¼Â¸½¤¹¤ë¤¿¤á¤Ë¤Ï¡¢ÉÔ´°Á´¤Ê·¿¤ò»ÈÍѤ·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£

struct a { struct b *bp; };
struct b { struct a *ap; };


°Û¤Ê¤ë·Á¼°¤Î¥Ý¥¤¥ó¥¿¤ä°Û¤Ê¤ë¼ïÎà¤Î¥Ç¡¼¥¿·¿¤ò»ý¤Ä¡¢¶¯ÎϤʷ¿°Í¸¥×¥í¥°¥é¥ß¥ó¥°¸À¸ì¤Ë¤Ï¡¢¤¹¤Ù¤Æ¾åµ­¤Î¤è¤¦¤Ê¥±¡¼¥¹¤ò½èÍý¤¹¤ë¤¿¤á¤ÎÊýË¡¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

Îã

ÉÔ´°Á´¤Ê¹½Â¤Âη¿¤ä¶¦ÍÑÂη¿¤Ë¤Ï typedef ̾¤ÎÄêµÁ¤¬ÌòΩ¤Á¤Þ¤¹¡£¥Ç¡¼¥¿¹½Â¤¤¬Ê£»¨¤Ê (¤ª¸ß¤¤¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò¿¿ô»ý¤Ä¤è¤¦¤Ê) ¾ì¹ç¤Ï¡¢¹½Â¤ÂΤؤΠtypedefs ¤Î¥ê¥¹¥È¤òÁ°Êý¤Ë (Ãæ¿´¤È¤Ê¤ë¥Ø¥Ã¥À¡¼¤Ë) »ØÄꤹ¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢Àë¸À¤¬´Êñ¤Ë¤Ê¤ê¤Þ¤¹¡£

typedef struct item_tag Item;
typedef union note_tag Note;
typedef struct list_tag List;
. . .
struct item_tag { . . . };
. . .
struct list_tag {
List *next; . . .
};


¤µ¤é¤Ë¡¢ÆâÍƤ¬¥×¥í¥°¥é¥à¤Î»Ä¤ê¤Ç»ÈÍѤǤ­¤Æ¤Ï¤¤¤±¤Ê¤¤¹½Â¤ÂΤ䶦ÍÑÂΤËÂФ·¤Æ¤Ï¡¢ÆâÍƤʤ·¤Î¥¿¥°¤ò¥Ø¥Ã¥À¡¼¤ËÀë¸À¤Ç¤­¤Þ¤¹¡£¥×¥í¥°¥é¥à¤Î¾¤ÎÉôʬ¤Ï¡¢²¿¤ÎÌäÂê¤â¤Ê¤¯ÉÔ´°Á´¤Ê¹½Â¤ÂΤ䶦ÍÑÂΤؤΥݥ¤¥ó¥¿¤ò»ÈÍѤǤ­¤Þ¤¹¡£¤¿¤À¤·¡¢¤½¤Î¥á¥ó¥Ð¡¼¤Ï»ÈÍѤǤ­¤Þ¤»¤ó¡£

ÉÔÆÃÄêĹ¤Î³°ÉôÇÛÎó¤ÏÉÔ´°Á´¤Ê·¿¤È¤·¤ÆÉÑÈˤ˻ÈÍѤµ¤ì¤Þ¤¹¡£°ìÈÌŪ¤Ë¡¢ÇÛÎó¤ÎÆâÍƤò»ÈÍѤ¹¤ë¤¿¤á¤Ë¡¢ÇÛÎó¤ÎÂ礭¤µ¤òÃΤëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£

¸ß´¹·¿¤ÈÊ£¹ç·¿

K&R C ¤Ç¤Ï (ANSI/ISO C ¤Î¾ì¹ç¤Ï¤µ¤é¤Ë¸²Ãø¤Ç¤¹¤¬)¡¢Æ±¤¸Í×ÁǤò»²¾È¤¹¤ë 2 ¤Ä¤ÎÀë¸À¤òÊ̤Τâ¤Î¤È¤·¤Æ°·¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£ANSI/ISO C ¤Ï¡¢¤³¤Î¤è¤¦¤Ê¡Ö¤¢¤ëÄøÅÙ»÷¤Æ¤¤¤ë¡×·¿¤ò¼¨¤¹¤¿¤á¤Ë¡¢¡Ö¸ß´¹·¿¡×¤È¤¤¤¦ÍѸì¤ò»ÈÍѤ·¤Þ¤¹¡£¤³¤ÎÀá¤Ç¤Ï¡¢¤³¤Î¸ß´¹·¿¤È¡¢2 ¤Ä¤Î¸ß´¹·¿¤ò·ë¹ç¤·¤¿¡ÖÊ£¹ç·¿¡×¤òÀâÌÀ¤·¤Þ¤¹¡£

Ê£¿ô¤ÎÀë¸À

C ¥×¥í¥°¥é¥à¤Ë¤ª¤¤¤Æ³Æ¥ª¥Ö¥¸¥§¥¯¥È¤Þ¤¿¤Ï´Ø¿ô¤ÎÀë¸À¤¬ 1 ÅÙ¤·¤«µö¤µ¤ì¤Æ¤¤¤Ê¤¤¤Î¤Ç¤¢¤ì¤Ð¡¢¸ß´¹·¿¤ÏɬÍפʤ¤¤Ï¤º¤Ç¤¹¡£¤·¤«¤·¡¢Æ±¤¸Í×ÁǤò»²¾È¤¹¤ëÊ£¿ô¤ÎÀë¸À¤òµö²Ä¤¹¤ë¥ê¥ó¥¯¡¢´Ø¿ô¤Î¥×¥í¥È¥¿¥¤¥×¡¢¤ª¤è¤Óʬ³ä¥³¥ó¥Ñ¥¤¥ë¤Ë¤Ï¡¢¤³¤Î¤è¤¦¤Êµ¡Ç½¤¬É¬ÍפǤ¹¡£Ê£¿ô¤ÎËÝÌõñ°Ì (¥½¡¼¥¹¥Õ¥¡¥¤¥ë) ´Ö¤Ç¤Ï¡¢·¿¤Î¸ß´¹À­¤Îµ¬Â§¤Ï 1 ¤Ä¤ÎËÝÌõñ°ÌÆâ¤Î¤â¤Î¤È¤Ï°Û¤Ê¤ê¤Þ¤¹¡£

ʬ³ä¥³¥ó¥Ñ¥¤¥ë´Ö¤Î¸ß´¹À­

³Æ¥³¥ó¥Ñ¥¤¥ë¤Ç¤ÏÊÌ¡¹¤Î¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤ò»²¾È¤¹¤ë¤¿¤á¡¢Ê¬³ä¥³¥ó¥Ñ¥¤¥ë´Ö¤Î¸ß´¹·¿¤ËÂФ·¤Æ¡¢¤Û¤È¤ó¤É¤Îµ¬Â§¤ÎÆâÍƤϼ¡¤Î¤è¤¦¤Ë¹½Â¤²½¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

¤µ¤é¤Ë¡¢¹½Â¤ÂΡ¢¶¦ÍÑÂΡ¢¤ª¤è¤ÓÎóµó·¿¤Î¥á¥ó¥Ð¡¼¤Î̾Á° (̾Á°¤Ê¤·¥á¥ó¥Ð¡¼¤Ë̾Á°¤¬¤Ê¤¤¤È¤¤¤¦¤³¤È) ¤â°ìÃפ·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤·¤«¤·¡¢¤½¤ì¤¾¤ì¤Î¥¿¥°¤Ïɬ¤º¤·¤â°ìÃפ¹¤ëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£

ñ°ì¤Î¥³¥ó¥Ñ¥¤¥ë¤Ç¤Î¸ß´¹À­

Ʊ¤¸¥¹¥³¡¼¥×Æâ¤Î 2 ¤Ä¤ÎÀë¸À¤¬Æ±¤¸¥ª¥Ö¥¸¥§¥¯¥È¤Þ¤¿¤Ï´Ø¿ô¤òµ­½Ò¤¹¤ë¤È¤­¡¢¤³¤Î 2 ¤Ä¤ÎÀë¸À¤Ï¸ß´¹·¿¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤³¤ì¤é 2 ¤Ä¤Î·¿¤Ï¼¡¤Ë¡¢ºÇ½é¤Î 2 ¤Ä¤È¸ß´¹À­¤ò»ý¤Ä¡¢1 ¤Ä¤ÎÊ£¹ç·¿¤Ë·ë¹ç¤µ¤ì¤Þ¤¹¡£Ê£¹ç·¿¤Ë¤Ä¤¤¤Æ¤Ï¸å¤ÇÀâÌÀ¤·¤Þ¤¹¡£

¸ß´¹·¿¤ÏºÆµ¢Åª¤ËÄêµÁ¤µ¤ì¤Þ¤¹¡£°ìÈÖ²¼¤Ï·¿»ØÄê»Ò¤Î¥­¡¼¥ï¡¼¥É¤Ç¤¹¡£¤³¤ì¤é¤Îµ¬Â§¤Ï¡¢unsigned short ¤Ï unsigned short int ¤ÈƱ¤¸¤Ç¤¢¤ê¡¢·¿»ØÄê»Ò¤Ê¤·¤Î·¿¤Ï int ¤ò»ý¤Ä·¿¤Ç¤¢¤ë¤³¤È¤ò¼¨¤·¤Þ¤¹¡£Â¾¤Î¤¹¤Ù¤Æ¤Î·¿¤Ï¡¢ÇÉÀ¸¸µ¤Î·¿¤¬¸ß´¹À­¤ò»ý¤Ä¤È¤­¤À¤±¡¢¸ß´¹À­¤ò»ý¤Á¤Þ¤¹¡£¤¿¤È¤¨¤Ð¡¢½¤¾þ»Ò const ¤È volatile ¤¬Æ±¤¸¤Ç¤¢¤ê¡¢Ì¤½¤¾þ·¿¤¬¸ß´¹À­¤ò»ý¤Ä¾ì¹ç¡¢2 ¤Ä¤Î½¤¾þ·¿¤Ï¸ß´¹À­¤ò»ý¤Á¤Þ¤¹¡£

¸ß´¹¥Ý¥¤¥ó¥¿·¿

2 ¤Ä¤Î¥Ý¥¤¥ó¥¿·¿¤¬¸ß´¹À­¤ò»ý¤Ä¤¿¤á¤Ë¤Ï¡¢¤³¤Î 2 ¤Ä¤Î¥Ý¥¤¥ó¥¿¤¬»Ø¤¹·¿¤¬¸ß´¹À­¤ò»ý¤Á¡¢2 ¤Ä¤Î¥Ý¥¤¥ó¥¿¤¬Æ±¤¸¤è¤¦¤Ë½¤¾þ¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¥Ý¥¤¥ó¥¿¤Î½¤¾þ»Ò¤Ï * ¤Î¸å¤Ë»ØÄꤵ¤ì¤ë¤³¤È¤òǰƬ¤ËÃÖ¤¤¤Æ¡¢¼¡¤ÎÎã¤ò¸«¤Æ¤¯¤À¤µ¤¤¡£

int *const cpi;
int *volatile vpi;


¾åµ­ 2 ¤Ä¤ÎÀë¸À¤Ï¡¢Æ±¤¸·¿ int ¤ò»Ø¤¹¤¬½¤¾þ¤¬°Û¤Ê¤ë 2 ¤Ä¤Î¥Ý¥¤¥ó¥¿¤òÀë¸À¤·¤Æ¤¤¤Þ¤¹¡£

¸ß´¹ÇÛÎó·¿

2 ¤Ä¤ÎÇÛÎ󷿤¬¸ß´¹À­¤ò»ý¤Ä¤¿¤á¤Ë¤Ï¡¢¤³¤Î 2 ¤Ä¤ÎÇÛÎó¤ÎÍ×ÁǤη¿¤¬¸ß´¹À­¤ò»ý¤¿¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£Î¾Êý¤ÎÇÛÎó¤Î·¿¤Î¥µ¥¤¥º¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢Î¾Êý¤Î¥µ¥¤¥º¤â°ìÃפ·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£¤Ä¤Þ¤ê¡¢ÉÔ´°Á´¤ÊÇÛÎó·¿ (¡ÖÉÔ´°Á´¤Ê·¿¡×¤ò»²¾È) ¤Ï¡¢Â¾¤ÎÉÔ´°Á´¤ÊÇÛÎ󷿤Ȥ⡢¥µ¥¤¥º¤¬»ØÄꤵ¤ì¤Æ¤¤¤ëÇÛÎ󷿤Ȥâ¸ß´¹À­¤ò»ý¤Á¤Þ¤¹¡£

¸ß´¹´Ø¿ô·¿

´Ø¿ô¤¬¸ß´¹À­¤ò»ý¤Ä¤¿¤á¤Ë¤Ï¡¢¼¡¤Îµ¬Â§¤Ë½¾¤ï¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£

ÆÃÊ̤ʾì¹ç

signed int ¤Ï int ¤ÈƱ¤¸¤è¤¦¤ËÆ°ºî¤·¤Þ¤¹¡£¤¿¤À¤·¡¢¥Ó¥Ã¥È¥Õ¥£¡¼¥ë¥É¤ÇÄ̾ï¤Î int ¤¬ unsigned Æ°ºî¤ò¼¨¤¹¿ô¤Ë¤Ê¤ë¾ì¹ç¤ò½ü¤­¤Þ¤¹¡£

¤Þ¤¿¡¢Îóµó·¿¤ÏƱ¤¸À°¿ô·¿¤È¸ß´¹À­¤ò»ý¤¿¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£°Ü¿¢²Äǽ¤Ê¥×¥í¥°¥é¥à¤Î¾ì¹ç¡¢¤³¤ì¤Ï¡¢Îóµó·¿¤¬Ê̤η¿¤Ç¤¢¤ë¤³¤È¤ò°ÕÌ£¤·¤Þ¤¹¡£°ìÈÌŪ¤Ë¡¢ANSI/ISO C µ¬³Ê¤Ï¤³¤Î¤è¤¦¤ËÎóµó·¿¤ò°·¤¤¤Þ¤¹¡£

Ê£¹ç·¿

2 ¤Ä¤Î¸ß´¹·¿¤«¤é 1 ¤Ä¤ÎÊ£¹ç·¿¤Ø¤ÎºîÀ®¤âºÆµ¢Åª¤ËÄêµÁ¤µ¤ì¤Þ¤¹¡£ÉÔ´°Á´¤ÊÇÛÎ󷿤ä¸Å¤¤·Á¼°¤Î´Ø¿ô·¿¤ò»ÈÍѤ¹¤ë¤³¤È¤Ë¤è¤ê¡¢¸ß´¹·¿¤ò¤ª¸ß¤¤¤Ë°Û¤Ê¤ë¤è¤¦¤Ë¤Ç¤­¤Þ¤¹¡£Æ±Íͤˡ¢Ê£¹ç·¿¤ÎºÇ¤â´Êñ¤Ëµ­½Ò¤¹¤ë¤Ë¤Ï¡¢¸µ¤ÎξÊý¤Î·¿ (¸µ¤Î·¿¤Î¤¹¤Ù¤Æ¤Î»ÈÍѲÄǽ¤ÊÇÛÎó¥µ¥¤¥º¤È¤¹¤Ù¤Æ¤Î»ÈÍѲÄǽ¤Ê¥Ñ¥é¥á¡¼¥¿¥ê¥¹¥È¤â´Þ¤à) ¤È·¿¤Î¸ß´¹À­¤ò»ý¤¿¤»¤ì¤Ð¤è¤¤¤Ç¤·¤ç¤¦¡£


¥µ¥ó¡¦¥Þ¥¤¥¯¥í¥·¥¹¥Æ¥à¥º³ô¼°²ñ¼Ò
Copyright information. All rights reserved.
¥Û¡¼¥à   |   Ìܼ¡   |   Á°¥Ú¡¼¥¸¤Ø   |   ¼¡¥Ú¡¼¥¸¤Ø   |   º÷°ú