Thread: How does one analysis difficult code and track variable manipulations in C++?

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    1

    How does one analysis difficult code and track variable manipulations in C++?

    I started reading Bjarne Stroustrup C++ Programming Practises and Principles. Recently I have been stuck on Chapter 6 and 7 with the Parser 'Simple Calculator' program the book was teaching.

    When analysing abstract programs its hard to know how functions and objects manipulate input streams and where it sends them after. In this book when he introduced parsing there are times when an object function calls a object where that object calls a recursion, where that recursion calls another method that calls two separate recursions.... it makes you wonder to yourself how you managed to learn and understand the derivation of the Gravitational Constant g but a simple calculator

    In V.S.I heard you can use the debugger and toggle checkpoints but there has to be a more efficient way when:

    You don't know where the code is going...


    Here it is:
    View Code Snippet ยป Code Viewer - Source Code Upload/Viewer


    My question is ~ how can I better analysis and keep track of the variable values of the input stream >> output stream. If you can help me use the debugger for such complexity I guess the question wont be opinion based..

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Most debuggers allow you to step through the code step by step while it is executing, GDB has a feature (i imagine others have as well) that will step into all function calls as they appear. If the code uses the STL a lot, then it will get hairy and hard to follow quickly though.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I know it's lame but I really like using print flags.

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by MutantJohn View Post
    I know it's lame but I really like using print flags.
    I don't think that's lame at all. It only becomes worse than using a debugger when you start putting debugging printf's all over the place. Then a debugger is better. And a debugger is better for quickly finding out exactly where a segfault is occurring.

    But if you're avoiding the debugger because you don't know how to use it, then it would be a good idea to learn. Debuggers in an IDE tend to be easier to learn.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. keeping track of code blocks
    By Aisthesis in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2009, 10:13 PM
  2. tools for static code analysis
    By lehe in forum C++ Programming
    Replies: 2
    Last Post: 03-18-2009, 12:41 PM
  3. Code Analysis
    By guesst in forum C++ Programming
    Replies: 8
    Last Post: 09-09-2008, 04:17 PM
  4. static code analysis
    By markucd in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2005, 06:27 AM
  5. very difficult code - program
    By gaurav_behl in forum C Programming
    Replies: 2
    Last Post: 06-15-2004, 11:33 PM