Revision as of 05:42, 11 July 2012 by Rhea (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


ECE264: Debugging with Print Statements

Although print statements are not a good way to debug code, they can be very useful for quick checks.  However, it can be very annoy and tedious to add and delete multiple lines if they are just used for debugging.  A quick and easy solution to this problem is to use #ifdef.   #ifdef is very similart to an if statement; it looks to see if a variable is definded.  If it is it will exicute the code following.  If it is not defined it will go to the #else, if no #else follows, then nothing will happen if it is not defined.


Example code for debugging:

  1. ifdef DEBUG

printf("This will be printed.\n");

  1. endif


To make DEBUG defined add -DDEBUG to the gcc statement when compiling.  To skip over the #ifdef, complie with gcc like normal.


Back to ECE264, Spring 2011, Prof. Lu



Back to ECE264

Alumni Liaison

Prof. Math. Ohio State and Associate Dean
Outstanding Alumnus Purdue Math 2008

Jeff McNeal