suggest me

This is a discussion on suggest me within the C Programming forums, part of the General Programming Boards category; hi iam learning c. can u suggest me the tutorial for debugging techiques and data structure in c thank u ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    90

    suggest me

    hi iam learning c.
    can u suggest me the tutorial for debugging techiques and data structure in c

    thank u
    dtrr

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,437
    http://www.cprogramming.com/tutorial/ maybe?
    Maybe not debugging, but for other things, at least.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A "non-debugging" debugging technique is to start small - don't try to write tons of code at once, then hope that it all works. With more experience you can get away with writing a bit more, but it's often better to do small portions, debug that, then write another bit, debug that, write some more, debug that, and so on, until the code is complete.

    Otherwise, debugging comes into three parts:
    1. Finding the faulty code.
    2. Fixing the faulty code.
    3. Validating the fix.

    #1 is usually the big portion, but #3 can be a major portion of work too in some cases, and #2 is almost always the smallest part.

    There are many methods, and usually there isn't "one method works for all". Some of those methods are:
    1. Defensive coding. To avoid bugs in the first place, or at least catch bugs EARLY [because a bug that has been "going along happily" for 20 function calls make it much harder to find], you should add statements such as "assert()" to catch things such as NULL-pointers, array indices out of bounds, negative numbers where you don't expect them, divide by zero, and anything else you "don't expect". Always have a "default" in switch statements, and if you have a if/else if/else chain, even if you THINK you have covered all possibilities, add an extra one to check for "none of the above". Preventing a potential bug from "getting loose" will save you time in the long run.

    2. Printlining - adding printf/cout statement to show where in the code you are, and what the values of critical variables are.

    3. Logging - similar to printlining, but a more permanent fixture in the code. Basicly, all functions [or all major functions] are set up with output statements that print important data to a logfile [or sometimes a serial port or similar]. Often logging is disabled by default, and enabled when you are looking for a problem.

    4. Splitting the code in portions - this helps identify a problem. Basically comment out or otherwise "don't use" some portions of code and see if that eliminates the problem. If it does, then you know that the commented out code is the problem. If it still persists, comment out some OTHER code and see if that helps. Hopefully, eventually, you will end up with ONE function [or a small portion of a function] that has the bug in it.

    5. Using a debugger to single-step, breakpoints and looking at variables. This is powerful as long as you have a good idea where to start looking. Many debuggers will also give you a good stack-trace (aka call-stack), showing which functions have been called to get to the point of the crash.

    One technique for using a debugger to identify the code that crashes is to "step over" functions until you hit the one that crashes. Then start over, mark that one with a breakpoint, run until that function, then step into that function. Repeat this process until you find the actual faulty function, then step through that function until you find the problem.

    Sometimes finding a problem with stepping is not possible - you may have to step millions of times to get through a function that draws a full screen pixel by pixel for example. In this case, you may want to find out "where it goes wrong", e.g. when x = 1024 and y = 760, and add an extra if-statement that you can set a breakpoint in. Using printlining to find the point of failure is one way that works here.

    6. Code review. If you have a decent idea of which function is wrong, you can just read the code, perhaps also using pen and paper to follow the code step by step. Pay particular attention to "edges", e.g. where loops end, if-statements and calculations at the upper or lower range of the value-range you expect.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    90
    thank u,
    while compling our code why we are using "-g" argument

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    gcc's -g switch tells the compiler to generate "debug info".
    This is used when you run the application in the debugger, e.g. gdb, allow you to see variables (by giving the debugger info about where each variable is stored) and connect the machine code that the compiler generates with the source-code that you wrote, so that when you say "Break func1" it knows where func1 is in the machine-code and can put a breakpoint on that address. It then uses this information for "stepping" to know where the next line of code is, etc, etc.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    You might like to read this. This author came up numerous times in my software eng. studies classes concerning development.

    http://virtualschool.edu/mon/Softwar...verBullet.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 03-10-2009, 11:05 PM
  2. Please suggest a good C++ textbook
    By puja399 in forum C++ Programming
    Replies: 7
    Last Post: 11-19-2005, 09:04 PM
  3. Please, suggest a project .
    By Dragon227Slayer in forum C# Programming
    Replies: 1
    Last Post: 06-12-2004, 11:16 AM
  4. Suggest A Compiler For ME!
    By skyruler54 in forum C++ Programming
    Replies: 19
    Last Post: 09-29-2002, 01:44 PM
  5. Suggest an interesting C++ project
    By unicef2k in forum C++ Programming
    Replies: 1
    Last Post: 12-17-2001, 06:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21