Visual Studio development environment enables you to test your compile-time, run-time, and logical errors by providing you a debug build option for your project. By using debug option, you can set breakpoints during compilation, watch the values of variables, registers, and threads and even you can change values of variables during compilation.
Debug versus Release build
There are two ways to build your project in VC++. One is debug version and other is release version. Microsoft uses separate MFC dlls for debug and release versions. If you will see MFC dlls in your system directory, its says MFC42d.dll and MFC42.dll for debug and release versions respectively. Debug version is to help programmers to help in detecting and correcting bugs in their programs.
Here are default options for debug and release build :
|
Version |
Default Values |
|
Win32 Debug |
Full symbolic debugging information in Microsoft format No optimization (optimization generally makes debugging more difficult) |
| Win32 Release |
No symbolic debugging information Optimized for maximum speed |
Error Types
During SDLC (Software Development Life Cycle), there are four types of errors.
Machine errors
Compile-time errors
Run-time errors
Logical and design errors
Machine errors are processor dependent and they are difficult to detect and correct. Since we use decimal system and values stored in the memory are in the form of bits. Lets say we devide a number 1.0 by 3. 1.0/3 = 3.333333....... and it goes till infinity. Processor can't store it and it truncates upto some level.
Compile-time errors are easy to find out. They are generally spelling mistakes or incorrect use of functions or parameters. For example, if i call AfxEnableControlContainer function as AfxEnablecontrolContainer, I get this error :
D:\samples\test\test.cpp(53) : error C2065: 'AfxEnablecontrolContainer' : undeclared identifier
Run-time errors occurs during program execution. Your program compiles fine but it blows up when you are doing something. Main cause of runtime errors is using unintialized variables. Here is an example:
int j ;
/* Do something and value of j = 12 */
j = 12 ;
For ( int i=0; j<10; j++ )
{
/* Do something */
}
So control will never execute this loop because value of j is greater than 10. The best way to get rid of this kinda bugs are proper initialization of variables.
Logical errors are very easy to do. They occur when your design or program logic is not correct. Here is an example with && operator
CRecordset recSet; /* Open recordset and something else */
If ( ! recSet.IsEOF() && recSet.IsBOF() ) // WRONG
{
/* Do something */
}
If ( ! ( recSet.IsEOF() && recSet.IsBOF() ) ) // CORRECT
{
/* Do something */
}
while I wanted to check if recordset is not empty then do something.