Thread: Large C file need to analyze

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    347

    Large C file need to analyze

    I have a large c project with several files. The problem is frequently i get issues and need to relook each and every variable for debugging. I need some tools which can generate a kind of all information as a flow chart etc which will be easy to understand and discuss with others. Please advise.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,416
    Quote Originally Posted by Satya
    I have a large c project with several files. The problem is frequently i get issues and need to relook each and every variable for debugging
    Just wondering, but have you tried to:
    • Refactor the code such that long functions with too many tasks that they handle by themselves are divided into smaller functions that do one thing and do it well. This should help you to avoid exceedingly long functions.
    • While refactoring, write automated unit and integration tests. These can help you both document how the code is to be used and pinpoint in which functions mistakes might be hiding. Since these functions only do one thing, it is easier to test that they do it well.
    • Refactor to avoid global variables like the plague; make all variables as local as possible. This ties in with having functions that only have one responsibility: you have fewer variables that need to be considered at any point in the code, hence it becomes easier to reason about the code (and you would no longer have to "relook each and every variable for debugging", since you can skip all the local variables in functions that perfectly pass extensive unit tests).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    What you say is correct but i am right now at every advance stage of project. So i am not sure at this stage i can take the risk of re writing the code.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,416
    Quote Originally Posted by Satya
    i am right now at every advance stage of project. So i am not sure at this stage i can take the risk of re writing the code.
    Can you take the risk of using "some tools which can generate a kind of all information as a flow chart etc which will be easy to understand and discuss with others", but which might help you and your team merely understand what you already know without helping you to fix the bugs you are having a hard time fixing?

    Anyway, I have not seriously used code visualisation tools myself, so I cannot recommend any, but you should be able to find what you're looking for by searching the Web with keywords such as "C code flowchart" or "C code visualization". I don't really see how they will help you though since you're not looking at understanding the general big picture flow of code, but actually debugging the nitty gritty of the code: at that level of detail, flowcharts don't really have an advantage over actually reading the code. Perhaps more specific static analysis tools might help, but then they often focus on potential bugs that you can eliminate... which will involve rewriting your code.

    By the way, are you using version control?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    What you said is correct. Thank you. I will try to rewrite the code. I am using git version control.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Analyze code in large systems
    By Chrys in forum C Programming
    Replies: 5
    Last Post: 11-18-2008, 01:14 PM
  2. [Large file][Value too large for defined data type]
    By salsan in forum Linux Programming
    Replies: 11
    Last Post: 02-05-2008, 04:18 AM
  3. Large file i/o
    By Mostly Harmless in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2007, 01:48 PM
  4. (psycho)analyze this!
    By Darkness in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-10-2005, 09:25 PM
  5. Please Help me Analyze Wave ..
    By toa2k in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2004, 03:20 PM

Tags for this Thread