1
我有以下代碼:段錯誤無效的長選項
struct option longopts[] =
{
{"version", no_argument, 0, 'v'}
};
if (argc > 1)
{
int c;
int longindex;
while ((c = getopt_long (argc, argv, "v", longopts, &longindex)) != -1)
{
switch (c)
{
case 'v':
puts (VERSION_INFO);
exit (0);
case '?':
exit (1);
}
}
}
爲什麼用--versio
(故意拼錯)的參數會導致段錯誤,但-a
(這也是一個無效的選項),它只是打印出屏幕上顯示「無效選項」消息?