Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Debugging (compilation)

Similar presentations


Presentation on theme: "Basic Debugging (compilation)"— Presentation transcript:

1 Basic Debugging (compilation)
Compiler errors occur when a program has incorrect syntax/construction messages may be cryptic, but… line numbers (where the error occurred) are provided Start on the line identified in the first error note: it may actually be before the listed line fix that error, then recompile sometimes errors cascade from an earlier error more than one error may disappear!

2 Functionality OK, program compiles and runs, but it’s wrong – now what? Insert diagnostic output statements using cout at locations where you suspect things are going wrong or other critical points in the code beginning and end of functions after complex calculations to display intermediate results, e.g. variables affected by each major algorithm step Remove extra output statements when problem is solved or use // to “comment them out”

3 Another Debugging/Testing technique
Use a compiler directive or a variable to activate print statements Avoids have to comment out print statements – just set/unset the variable, but… It has runtime overhead: the if statement always gets executed… // this goes at the top of the file (set to 0 to turn it off) #define DEBUG 1 or, as a global const DEBUG=1; // example: somewhere in the file a random function… void somefunction() { If(DEBUG) { cout << “entered somefunction()…” << endl; } … function statements … }

4 Common Programming Errors
Omitting braces ( { }) Omitting a closing brace ( } ) Misuse of = for == Missing statement end “;”


Download ppt "Basic Debugging (compilation)"

Similar presentations


Ads by Google