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

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang