Command line argument list discrepancy between deb

2019-07-14 04:30发布

I had this bite me in a certain sensitive spot this evening, and would like some clarification. As karlphillip said in this question, the executable sees the argument list as

Consider: ./program file.txt

argv[0] is "program"
argv[1] is "file.txt"

However, in the gdb debugger, for the program ./lc1 f1.txt, the arglist shows as

arg[0] is "/home/jason/Project 6/lc1"
arg[1] is "lc1"
arg[2] is "f1.txt"

Why the discrepancy between the two arglists?

1条回答
该账号已被封号
2楼-- · 2019-07-14 05:21

I can't reproduce that error. How are you running it on the gdb prompt?

I'm guessing you have

(gdb) run lc1 f1.txt

which is wrong. In the gdb prompt, it's supposed to be

(gdb) run f1.txt

That will reconcile with your normal execution.

查看更多
登录 后发表回答