[OT] Debugging and Logging

Discussion in 'C Programming' started by v4vijayakumar, Jul 14, 2006.

  1. Which of the following is the right way to debug/log in C?

    1. using '#ifdef DEBUG' and compiling with '-DDubug'
    2. defining and implementing 'log(loglevel, logmessage)' function
    3. defining and implementing separate functions like, info(logmessage),
    warn(logmessage), panic(logmessage), etc.

    is it also possible to have debug/log functions in the code with out
    incresing executable code size?

    Thanks in advance.
     
    v4vijayakumar, Jul 14, 2006
    #1
    1. Advertisements

  2. v4vijayakumar

    Ian Collins Guest

    That's one way.
    and that's another. Which you choose is a matter of style.
    Can you fill your bath to the brim and get in without flooding the floor?
     
    Ian Collins, Jul 14, 2006
    #2
    1. Advertisements

  3. "DEBUG" and "Dubug" differ in four of the five characters. That is
    unlikely to work.
    All of these are possible partial answers, given adequate specification
    and correct spellings. Since the defining of a DEBUG macro does nothing
    in itself, and there is no way to know what your named functions would
    do, nothing more can be said.
    You cannot increase the size of the program without increasing the size
    of the program.

    You may be able to use a debugger for your implementation which can make
    all of your choices (1-3) irrelevant and allow you to use code for
    debugging with no visible increase in code, but then the debugger's code
    and bookkeeping will be an added load during debugging itself.
     
    Martin Ambuhl, Jul 14, 2006
    #3
  4. v4vijayakumar

    Eric Sosman Guest

    What is "the" right color for paint?

    To my eye you've really only shown two alternatives: (1)
    and (2,3), the latter differing only in syntax. (1) is
    appropriate for some purposes, (2) for others. Observe that
    the two can be combined: You might place logging calls inside
    #ifdef DEBUG (or Dubug) ... #endif.
    Perhaps, perhaps not. In some situations, adding code
    may even make the executable smaller. Exactly what goes on
    varies from one implementation to another and depends very
    much on the precise circumstances; it's really not a question
    that can be answered from the point of view of the C language.
    (In fact, it can't even be *asked* from that point of view:
    C has no notion of the "size" of executable code.)
     
    Eric Sosman, Jul 14, 2006
    #4
  5. Eric Sosman said:
    Green.
     
    Richard Heathfield, Jul 14, 2006
    #5
  6. v4vijayakumar

    Dann Corbit Guest

    To debug, use a debugger.
    To log, use a log method.
    [snip]
     
    Dann Corbit, Jul 15, 2006
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.