It's been a while since I contributed to this forum so I thought I would share macros that I use to help with the development of programs. The attached zip file contains the include file, DebuggingAid.h, that contains a set of macros for debugging together with a demonstration program.
Features
1. The facility to output formatted strings to a console. The formatted string can contain variable values. I found a feature similar to this invaluable in PureBasic.
2. Displays programmer's messages during compiling in the window under the project tab. The message includes the file and line number of the source code. Double clicking on the message takes the programmer to the relevant part of the code, so this can be used as a placeholder/bookmark.
3. An Assertion macro that is similar to the assert macro in the C language - I included this macro so that all the debugging facilities are in one module. This macro shows the name of the module that has an error, the line number on which it occurred and the expression that triggered the error. Unlike the assert macro in C, this does not show the function where the error occurred, but it has a neater display.
The program stops running after the Assertion macro responds to an error.
The features can be used with ANSII or Unicode.
Usage
Include the header file in the module to be debugged:
#include "DebuggingAid.h"
To ensure the features are available, ensure that the line
#define DebuggingOn
is not commented out in the include file.
If this line is commented out then the macros for displaying messages to the console and the Assertion macro will be replaced by a blank line in the compiled code. However, the macro to display messages while compiling programs will still be available.
To use Unicode, uncomment the lines
//#define UNICODE //Windows
//#define _UNICODE //C runtime
Displaying messages and variables in a console.
To open a console for receiving messages at run time, include the macro OpenConsole in a program module. I usually include this line in response to the WM_CREATE message that is sent to the main window.
To write to the console, use the macro ConsoleOutput. The first argument of this macro is a formatted string that uses the same convention as the function wsprintf() ie include place holders such as %s for a string and %i for an integer. Include the values of these placeholders after the formatted string, separated by commas.
Example:
ConsoleOutput("Variable value: %d\n", 5);
ConsoleOutput("This is %s number %i", TEXT("test"), 7);
Displaying messages when compiling a program
This uses the MSGCOMPILE macro that must be implemented using a #pragma directive.
The message should not be placed in quote marks.
Example:
#pragma MSGCOMPILE(Need to insert code for this function later)
Using the ASSERTION macro
Use the macro ASSERTION followed by an expression in brackets. If the expression is FALSE then a message box displays the module and line number of where the error occurred, together with the expression.
Conclusion
If anybody has any other debugging macros that help with programming then post them here and I will add them to the attached file.