我正在学习如何使用getopt和*getopt_long*.一个问题是,当我使用gdb逐步运行以下简单程序时,optarg始终为0x0.
你知道为什么吗?这是gdb的问题吗?
我试图搜索网络并查看程序的汇编代码,但尚未找到答案.
调试代码表明optarg按预期指向agv [3](值"16").
#include <unistd.h>
#include <getopt.h>
#include <stdio.h>
static struct option options[] =
{
/* name has_arg flag val */
{ "num", 1, NULL, 'n' },
{ NULL , 0, NULL , 0 }
};
int main(int argc, char** argv)
{
int option;
option = getopt_long( argc, argv, "n:", options, NULL );
if (option == 'n') {
printf("%s\n", optarg);
if (optarg == NULL)
printf("optarg == NULL\n");
if (optarg == …Run Code Online (Sandbox Code Playgroud)