I am trying to figure out if various Microchip constants that were the result of a #define earlier in program execution were defined or not at run time while I'm stepping through code with a debugger. Is there an easy way to do that? Can I somehow add the constants names to the watch window or something? MPLAB doesn't seem to want to let me do that, or I'm doing it wrong.
Not a very helpful answer Nigel. There have been plenty of times when I wanted to check the value of a constant that's derived from a formula in the define statement.
Hi Josh. You can probably use an instruction that stores the constant value in a variable to check the value. Then delete that instruction afterwards.
You've obviously never looked at some of the Microchip code. You can spend a long time and have to look through several files to find out if a constant is defined or not. There USB code is about the worst example I've seen for this.
Thanks for the help folks. Yeah, tell me about it when it comes to Microchip and their love of constants. Mike (K8LH), you're saying to transfer the constant's value to a variable, and then track the value of the variable in the watch window? I never thought of that...brilliant!
if you want to know if it was DEFINED or not, you can do that at compile time. I do that a good bit when I'm not 100% certain that certain defines are valid inside of header files. For instance, some code might say something like:
What you asked was how to you tell if the define was defined at that point...
Code:
#if USE_SHIFT_METHOD
#warning using SHIFT method
variable >>= 3;
#else
#warning using stupid divide :(
variable /= 8;
#endif
Or something else you can do is
Code:
#ifdef USE_SHIFT_METHOD
#warning using shift method
#else
#error stupid divides! // the error directive will cause the compile to fail
#endif
I don't know if this is what you actually want to do or not, but #define's don't always have a value. For instance, if you compile in debug mode, __DEBUG is defined, but it isn't defined as anything. I don't know if you can transfer that to a variable as in variable=__DEBUG, but I do use it to do things like
Code:
General_Exception_Handler( stuff that goes here )
{
#ifdef __DEBUG
software breakpoint assembly instruction
#endif
}