Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For reference, I am a JavaScript developer learning C++. The browser is a pretty

ID: 658507 • Letter: F

Question

For reference, I am a JavaScript developer learning C++. The browser is a pretty powerful debugger, and I can easily place a breakpoint in my code, hover over a variable or expression and get the value of that expression. Is this even possible in C++ or am I in a different world entirely?

I'm starting to write a bit of C++ code for an online course, and debugging with Code::Blocks gives me very opaque information. For example, I see stuff like this: 0x8049bc3 push   ebp in the 'watches' window. Even if I write something like int foo = 3;, I have found no way of telling that foo is 3 while I'm stepping through my code. Am I missing something?

Explanation / Answer

You need to build a debug version of your program:

Make sure that the project is compiled with the -g (debugging symbols) compiler option on, and the -s (strip symbols) option off. This ensures that the executable has debug symbols included. Compiler optimization switches should be turned off, stripping symbols (-s) must be turned off.

C++ compiles into machine code, where variables are just memory addresses. Symbols, such as variable names, can be appended to the executable by using appropriate compiler flags.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote