小编Duk*_*uke的帖子

为什么gdb一直将optarg显示为0x0

我正在学习如何使用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)

c gdb getopt getopt-long

5
推荐指数
1
解决办法
455
查看次数

标签 统计

c ×1

gdb ×1

getopt ×1

getopt-long ×1