That's a somewhat obscure feature which has been in C since long before ANSI/ISO; 'xxxx' is not a null-terminated character string like "xxxx" which would be stored byte-wise. It depends on your system being capable of storing that group of characters in a way similar to that suggested by your quoted usage, so it's non-portable. Of course, nowadays, 4 characters are expected to fit in a long, but there's also the possibility that a string was meant rather than a multi-character constant.
编译以下代码时出现的问题。
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include "args.h"
int main (int argc, char * argv[])
{
int next_opt;
const char * const short_opts = "hl:";
const struct option long_opts [] = {
{"help", 0, NULL, 'h'},
{"load", 1, NULL, 'l'},
{NULL, 0, NULL, 0}
};
prgm_name = argv[0];
do {
next_opt = getopt_long(argc, argv, short_opts, long_opts, NULL);
switch (next_opt) {
case 'h' :
prt_usage(stdout, 0);
case 'l' :
break;
case '?' :
prt_usage(stderr, 1);
case '-1' :
/*不同机器对被单引号引起的多个字符的处理方式会有所不同。故而,编译器会报
出以上警告信息。*/
break;
default :
abort();
}
} while (next_opt != -1);
return 0;
}
void prt_usage (FILE * stream, int exit_co
{
fprintf (stream, "Usage : %s options.\n", prgm_name);
fprintf (stream, "-h --help Displays this usage information.\n" \
"-l int dur --load int dur Set interval and duration of average load.\n");
exit (exit_co
}