C

getopt, getopt_longについて

getopt #include <unistd.h> int getopt(int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; optstringにはオプションで指定できる文字のリストになっていて、引数を取る場合にはその文字の直後に:を付</unistd.h>…

可変長引数のマクロ

__VA_ARGS__で可変長引数のマクロを実現できる。 example #include <stdio.h> #define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) #define DEBUG_PRINT2(...) fprintf(__VA_ARGS__, 22) int main(int argc, char **argv) { char *name = "Taro"; int i</stdio.h>…

可変長引数の関数

va_listという型があり、これを使って可変長引数リストを操作できる。 va_listは、SYSTEM_DATA_TYPES(7)に説明がある。 example #include <stdio.h> static void myprintf(char *first_arg, ...) { va_list ap; va_start(ap, first_arg); printf("%s\n", va_arg(ap, c</stdio.h>…