0
次は、http://www.gnu.orgのコード例です。確かにほとんどの人が見るように、それはgetoptであり、私は変数の宣言について質問しています。なぜタイプや何も書かれていないのですgetoptのopterr宣言
opterr = 0;
これまで私はこれまで見たことがありません。
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main (int argc, char **argv)
{
int aflag = 0;
int bflag = 0;
char *cvalue = NULL;
int index;
int c;
opterr = 0;
while ((c = getopt (argc, argv, "abc:")) != -1)
switch (c)
{
case 'a':
aflag = 1;
break;
case 'b':
bflag = 1;
break;
case 'c':
cvalue = optarg;
break;
case '?':
if (optopt == 'c')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
default:
abort();
}
printf ("aflag = %d, bflag = %d, cvalue = %s\n",
aflag, bflag, cvalue);
for (index = optind; index < argc; index++)
printf ("Non-option argument %s\n", argv[index]);
return 0;
}
「optarg」がどこから来るのか尋ねるのは面白いです。 – user0042
あなたが選んだIDEは、関数 "Show Declaration"(または同様のもの)をサポートしているかもしれません。たとえば、Eclipse CDTでは、ボタン "F3"ですが、変数を右クリックしてこの関数を手動で選択することもできます。 – xMutzelx