I just finished programming a large project in C. I have a lot of debugging code (printfs and what not within the code). Now those debugging statements are a performance overhead and I want to remove them but they are very helpful in the future for trouble shooting purposes. What are the best practices to put the debug code in the code base. I have across many options.
Use a terminal argument (let's say
-d
) to specify if the executable should run in debug mode or not. The advantage is that the code will not change later. The disadvantage is that the code will be full of conditionals to check if the program is in debug mode or notThe other solution is to use some C macros for debugging. I don't quite understand how this works. It seems like you would define
d_printf
that would beprintf
if you are in debug mode and nothing if you are in not. But I guess this will requires recompiling the code every time you change from a debug mode to a non debug mode.
Can experienced C professionals advise about what the best practises are?