Rechercher une page de manuel
stdarg
Langue: ja
Version: 2001-10-14 (openSuse - 09/10/07)
Section: 3 (Bibliothèques de fonctions)
̾Á°
stdarg, va_start, va_arg, va_end, va_copy - ¸Ä¿ô¡¦·¿¤¬²ÄÊѤʰú¿ô¥ê¥¹¥È½ñ¼°
#include <stdarg.h>void va_start(va_list ap, last);
type va_arg(va_list ap, type);
void va_end(va_list ap);
void va_copy(va_list dest, va_list src);
ÀâÌÀ
´Ø¿ô¤Ï¸Æ¤Ó½Ð¤·¤ËºÝ¤·¤Æ¡¢¸Ä¿ô¤ä·¿¤¬²ÄÊѤʰú¿ô¤ò¤È¤ë¤³¤È¤¬¤Ç¤¤ë¡£ ¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë <stdarg.h> ¤Ç¤Ï va_list ·¿¤¬Àë¸À¤µ¤ì¤Æ¤ª¤ê¡¢3 ¤Ä¤Î¥Þ¥¯¥í¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£¤³¤ì¤é¤òÍѤ¤¤ë¤È¡¢ ¸Æ¤Ó½Ð¤µ¤ì¤¿´Ø¿ô¦¤Ç¤Ï¸Ä¿ô¤ä·¿¤òÃΤé¤Ê¤¤°ú¤¿ô¤Î¥ê¥¹¥È¤ò¡¢½ç¤Ë°ì ¤Ä¤Å¤ÄÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤ë¡£¸Æ¤Ó½Ð¤µ¤ì¤ë´Ø¿ô¤Ç¤Ï¡¢ va_list ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤¬Àë¸À¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤³¤Î¥ª¥Ö¥¸¥§¥¯¥È¤¬ va_start(), va_arg(), va_end() ¤Î³Æ¥Þ¥¯¥í¤Ë¤è¤Ã¤Æ°·¤ï¤ì¤ë¡£
va_start
va_start() ¥Þ¥¯¥í¤ÏºÇ½é¤Ë¸Æ¤Ó½Ð¤µ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤³¤ì¤Ï ap ¤ò½é´ü²½¤·¡¢ va_arg() ¤È va_end() ¤ÇÍѤ¤¤ë¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤Ë¤¹¤ë¡£¥Ñ¥é¥á¡¼¥¿¡¼ last ¤Ï°ú¤¿ô¥ê¥¹¥È¤Î¤¦¤Á¡¢²ÄÊѤÊÉôʬ¤ÎľÁ°¤ËÃÖ¤«¤ì¤ë¥Ñ¥é¥á¡¼¥¿¡¼¤Î̾Á°¤Ç¤¢ ¤ë¡£¤Ä¤Þ¤ê¸Æ¤Ó½Ð¤µ¤ì¤¿´Ø¿ô¤¬·¿¤òÃΤäƤ¤¤ëºÇ¸å¤Î°ú¤¿ô¤Ç¤¢¤ë¡£
¤³¤Î¥Ñ¥é¥á¡¼¥¿¡¼¤Ï¥ì¥¸¥¹¥¿ÊÑ¿ô¤ä´Ø¿ô¡¢ÇÛÎó¤È¤·¤Æ Àë¸À¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î¥Ñ¥é¥á¡¼¥¿¡¼¤Î¥¢¥É¥ì¥¹¤¬ va_start() ¥Þ¥¯¥í¤ÇÍѤ¤¤é¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
va_arg
va_arg() ¥Þ¥¯¥í¤Ï¡¢¸Æ¤Ó½Ð¤·»þ¤Ë»ØÄꤵ¤ì¤¿°ú¤¿ô¤Î¤¦¤Á¡¢ ¼¡¤Î°ÌÃ֤ˤ¢¤ë¤â¤Î¤ò»ØÄꤷ¤¿·¿ type ¤ÎÃͤȤ·¤Æ¼èÆÀ¤¹¤ë¡£ ¥Ñ¥é¥á¡¼¥¿¡¼ ap ¤Ï va_list ap ¤Ç¡¢ va_start() ¤Ë¤è¤Ã¤Æ½é´ü²½¤µ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¡£ va_arg() ¤ò¸Æ¤Ó½Ð¤¹¤´¤È¤Ë ap ¤ÏÊѹ¹¤µ¤ì¡¢¼¡²ó¤Î¸Æ¤Ó½Ð¤·¤ÎºÝ¤Ë¡¢¤µ¤é¤Ë¼¡¤Î°ú¤¿ô¤òÊÖ¤¹¤è¤¦¤Ë¤Ê¤ë¡£ ¥Ñ¥é¥á¡¼¥¿¡¼ type ¤Ï·¿¤Î̾Á°¤Ç¤¢¤ë¡£ type ¤ÎÁ°¤Ë * ¤òÉÕ¤±¤ì¤Ð¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î·¿ÉÕ¤¥Ý¥¤¥ó¥¿¤¬ÆÀ¤é¤ì¤ë¡£va_start() ¥Þ¥¯¥í¤Îľ¸å¤Ë va_arg() ¤òºÇ½é¤Ë¼Â¹Ô¤¹¤ë¤È¡¢ last ¤Î¼¡¤Î°ú¤¿ô¤¬Ê֤롣³¤±¤Æ¼Â¹Ô¤¹¤ë¤È¡¢»Ä¤ê¤Î°ú¤¿ô¤¬¤½¤ì¤¾¤ìÊ֤롣
¼¡¤Î°ú¤¿ô¤¬¤Ê¤«¤Ã¤¿¤ê¡¢ type ¤¬¼¡¤Î°ú¤¿ô¤Î¼ÂºÝ¤Î·¿¤È¸ß´¹¤Ç¤Ê¤¤¾ì¹ç (¥Ç¥Õ¥©¥ë¥È¤Î°ú¤¿ôÊÑ´¹¤Ç°· ¤¨¤Ê¤«¤Ã¤¿¾ì¹ç) ¤Ë¤Ï¡¢Í½Â¬¤Ç¤¤Ê¤¤¥¨¥é¡¼¤¬µ¯¤³¤ë¡£
ap ¤¬ va_arg(ap,type) ¤Î·Á¤Ç´Ø¿ô¤ËÅϤµ¤ì¤ë¤È¡¢ ap ¤ÎÃͤϴؿô¤«¤éÊ֤äÆÍ褿¸å¤ÏÉÔÄê¤È¤Ê¤ë¡£
va_end
va_start() ¤¬¼Â¹Ô¤µ¤ì¤ëËè¤Ë¡¢Æ±¤¸´Ø¿ôÆâ¤ÇÂбþ¤¹¤ë va_end() ¤¬¼Â¹Ô¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£ va_end(ap) ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¸å¡¢ÊÑ¿ô ap ¤ÎÃͤÏÉÔÄê¤È¤Ê¤ë¡£ va_start() ¤È va_end() ¤ÎÁȤò²¿²ó¤âʤ٤ƻȤ¦¤³¤È¤â²Äǽ¤Ç¤¢¤ë¡£ va_end() ¤Ï¥Þ¥¯¥í¤«¤â¤·¤ì¤Ê¤¤¤·´Ø¿ô¤«¤â¤·¤ì¤Ê¤¤¡£va_copy
¤¹¤°Ê¬¤«¤ë va_list ¤Î¼ÂÁõ¤Ï¡¢variadic ¤Ê´Ø¿ô¤Î¥¹¥¿¥Ã¥¯¥Õ¥ì¡¼¥à¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£ ¤³¤Î¤è¤¦¤Ê¾ì¹ç(¤Û¤È¤ó¤É¤Ï¤½¤¦¤Ç¤¢¤ë)¡¢ ñ¤Ë°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ì¤Ð¤¤¤¤¤è¤¦¤Ë»×¤¨¤ë¡£-
va_list aq = ap;
-
va_list aq; *aq = *ap;
-
va_list aq; va_copy(aq, ap); ... va_end(aq);
½àµò
va_start(), va_arg(), va_end() ¥Þ¥¯¥í¤Ï C89 ½àµò¤Ç¤¢¤ë¡£ va_copy() ¤Ï C99 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£Ãí°Õ
¤³¤ì¤é¤Î¥Þ¥¯¥í¤Ï¡¢°ÊÁ°¤«¤éÍѤ¤¤é¤ì¤Æ¤¤¿Æ±Åù¤Î¥Þ¥¯¥í·²¤È ¸ß´¹¤Ç¤Ï¤Ê¤¤¡£²áµî¤Î¤â¤Î¤È¸ß´¹¤Ê¥Ð¡¼¥¸¥ç¥ó¤Ï¡¢ ¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë varargs.h ¤Ë¸ºß¤¹¤ë¡£Îò»ËŪ¤Ê¥»¥Ã¥È¥¢¥Ã¥×¤Ï°Ê²¼¤Î¤È¤ª¤ê¤Ç¤¢¤ë¡£
#include <varargs.h> void foo(va_alist) va_dcl { va_list ap; va_start(ap); while(...) { ... x = va_arg(ap, type); ... } va_end(ap); }va_start ¥Þ¥¯¥í¤Ë '{' ¤ò´Þ¤ß¡¢ va_end ¥Þ¥¯¥í¤ËÂбþ¤¹¤ë '}' ¤ò´Þ¤à¥·¥¹¥Æ¥à¤â¤¢¤ë¤Î¤Ç¡¢ ¤³¤ÎÆó¤Ä¤Î¥Þ¥¯¥í¤ÏƱ¤¸´Ø¿ô¤Ë¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
¥Ð¥°
varargs ¥Þ¥¯¥í¤È¤Ï°Û¤Ê¤ê¡¢ stdarg ¥Þ¥¯¥í¤Ç¤Ï¸ÇÄê°ú¤¿ô¤Ê¤·¤Ç´Ø¿ô¤ò»ØÄꤹ¤ë¤³¤È¤¬µö¤µ¤ì¤Æ¤¤¤Ê¤¤¡£ ¤³¤ì¤Ï varargs ¥Ù¡¼¥¹¤Î¥³¡¼¥É¤ò stdarg ¤Î¥³¡¼¥É¤Ë½ñ¤´¹¤¨¤ë¤È¤¤Ë¡¢ÌÌÅݤʺî¶È¤Î¤â¤È¤Ë¤Ê¤ë¡£ ¤Þ¤¿¡¢¤¹¤Ù¤Æ¤Î°ú¤¿ô¤ò va_list ¤È¤·¤Æ²ÄÊѸĻØÄꤷ¤¿¤¤¤è¤¦¤Ê¾ì¹ç (vfprintf(3) ¤Ê¤É) ¤Ë¤â¾ã³²¤È¤Ê¤ë¡£Îã
´Ø¿ô foo ¤Ï½ñ¼°Ê¸»ú¤«¤é¤Ê¤ëʸ»úÎó¤ò¼õ¤±Æþ¤ì¡¢¤½¤Î½ñ¼°Ê¸»ú¤ËÂбþ¤¹¤ë·¿¤Ç²ÄÊѸĤΠ°ú¤¿ô¤òÆɤ߹þ¤ß¡¢°õ»ú¤¹¤ë¡£-
#include <stdio.h> #include <stdarg.h> void foo(char *fmt, ...) { va_list ap; int d; char c, *s; va_start(ap, fmt); while (*fmt) switch(*fmt++) { case 's': /* string */ s = va_arg(ap, char *); printf("string %s\n", s); break; case 'd': /* int */ d = va_arg(ap, int); printf("int %d\n", d); break; case 'c': /* char */ /* need a cast here since va_arg only takes fully promoted types */ c = (char) va_arg(ap, int); printf("char %c\n", c); break; } va_end(ap); }
Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre