I am using ubuntu 12.04 and Qt Creator 2.4.1. It builds my C code by default GCC.
I am debugging my program (Qt Creator (uses GDB)) and can already see lots of variables that would be called/created in the later steps of the program. Is it normal to see all variables in the beginning of the program? In another word, do I see the variables in the early stage of the program because of the debug option (-g)? For example, I ‘step into’ the code and stops in the first step which is int main()
char[1000] mesg; is executed on the 129th line however, I can see it and its memory address already. or int tem_hopt_dist=0; is on the line 230 but I already see its value as ‘3’.
Yes, this is normal. The debugger does not understand all the scoping semantics of the language, and displays data as if all the variables were initialized in their final memory locations even when they’re out of scope.
Some debuggers are better than others. This is a frequent source of irritation, for example if you are in the habit of having separate index variables all called
i, and the debugger won’t differentiate between them.