(One intermediate revision by one other user not shown)
Line 1: Line 1:
[[Category:ECE264]]
+
[[Category:ECE264]] [[Category:Programming]] [[Category:C]]
  
=Debugging Print Statement=
+
= [[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.
  
  
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.
 +
 
 +
----
 +
[[2011_Spring_ECE_264_Lu|Back to ECE264, Spring 2011, Prof. Lu]]
 +
 
 +
 
 +
<br> [[ECE264|Back to ECE264]]
 +
 
 +
[[Category:ECE264]]

Latest revision as of 05:42, 11 July 2012


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