刚刚纳入getopt
我的main()
功能
getopt
optarg
为每次调用设置全局变量
在调用后总是(例如)单步main()
执行gdb
,但仍按预期输出 cmd 行 arggetopt()
optarg
NULL
(gdb) p optarg
printf("%s\n", optarg)
这是怎么回事?为什么两者不一样?
这是 gdb 的问题以及它如何尝试检查全局变量还是发生了其他事情?
可能相关:错误 13800 - gdb 不打印与 getopt 相关的值的正确值
另请注意,即:
(gdb) n
opt: 111, arg,
0x804a040
0x804a034
0x804a020
0x804a030
(gdb) printf "%p\n%p\n%p\n%p\n", &optarg, &opterr, &optind, &optopt
0x2ae760
0x2ab0f4
0x2ab0f8
0x2ab0f0
在哪里:
(gdb) l
6 int main(int argc, char *argv[])
7 {
8 int c;
9 while ((c = getopt(argc, argv, ":abf:o:")) != -1) {
10 printf("opt: %d, %s, \n"
11 "%p\n%p\n%p\n%p\n",
12 c, optarg,
13 &optarg, &opterr, &optind, &optopt);