[OT] Debugging and Logging

V

v4vijayakumar

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.
 
I

Ian Collins

v4vijayakumar said:
Which of the following is the right way to debug/log in C?

1. using '#ifdef DEBUG' and compiling with '-DDubug' Eh?

2. defining and implementing 'log(loglevel, logmessage)' function
That's one way.
3. defining and implementing separate functions like, info(logmessage),
warn(logmessage), panic(logmessage), etc.
and that's another. Which you choose is a matter of style.
is it also possible to have debug/log functions in the code with out
incresing executable code size?
Can you fill your bath to the brim and get in without flooding the floor?
 
M

Martin Ambuhl

v4vijayakumar said:
Which of the following is the right way to debug/log in C?

1. using '#ifdef DEBUG' and compiling with '-DDubug'

"DEBUG" and "Dubug" differ in four of the five characters. That is
unlikely to work.
2. defining and implementing 'log(loglevel, logmessage)' function
3. defining and implementing separate functions like, info(logmessage),
warn(logmessage), panic(logmessage), etc.

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.
is it also possible to have debug/log functions in the code with out
incresing executable code size?

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.
 
E

Eric Sosman

v4vijayakumar said:
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.

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.
is it also possible to have debug/log functions in the code with out
incresing executable code size?

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.)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top