Line 1: Line 1:
[[Category:ECE264]]
+
<br>
  
=Debugging Print Statement=
+
= Debugging with Print Statements =
  
 +
Although print statements are not a good way to debug code, they can be very useful for quick checks. &nbsp;However, it can be very annoy and tedious to add and delete multiple lines if they are just used for debugging. &nbsp;A quick and easy solution to this problem is to use #ifdef. &nbsp; #ifdef is very similart to an if statement; it looks to see if a variable is definded. &nbsp;If it is it will exicute the code following. &nbsp;If it is not defined it will go to the #else, if no #else follows, then nothing will happen if it is not defined.
  
  
Put your content here . . .
 
  
 +
Example code for debugging:
  
 +
#ifdef DEBUG
  
 +
printf("This will be printed.\n");
  
[[ ECE264|Back to ECE264]]
+
#endif
 +
 
 +
<br>
 +
 
 +
To make DEBUG defined add -DDEBUG to the gcc statement when compiling. &nbsp;To skip over the #ifdef, complie with gcc like normal.
 +
 
 +
<br>
 +
 
 +
<br> [[ECE264|Back to ECE264]]
 +
 
 +
[[Category:ECE264]]

Revision as of 12:19, 30 April 2011


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

Alumni Liaison

To all math majors: "Mathematics is a wonderfully rich subject."

Dr. Paul Garrett