We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, Does anyone here ever use #message in other compilers? It is a useful tool for making sure that code with many #ifdef compiles the way you want without adding to the number of warnings. thanks, Martin
its simple #ifdef I_WANT_AN_ERROR_MESSAGE I screwed up #endif Will work just fine Erik
I should have been more clear, here is an example. At the top of your code you have the following #defines #define DEBUG #define PORT_PINS_ON ..... // there may be lots of these //#define PUT_IN_IMPORTANT_CUSTOMER_CODE in your code you put: #ifdef DEBUG #message "Compiled in debug" //c debug source code #else #message "No debug" //c debug source code #endif #ifdef PUT_IN_IMPORTANT_CUSTOMER_CODE #message "The customer will be happy you put back in their code, this code slows things down during debug or masks an issue so you took it out, but all is well now" //c debug source code #else #message "You just compile this code in a way that makes the cusomer mad, but is not a big deal to you" //c debug source code #endif When you compile your code, you see: Compiled in debug You just compile this code in a way that makes the cusomer mad, but is not a big deal to you Both of these conditions are not errors. You might argue that the customer code is a warning, but it would have been nice to know that you compiled in debug instead of having to burn a chip and test it to find out. This is just an example. Sometimes if your code is made to run in many different ways based on the hardware you run the code on, it helps to get messages.
At the top of your code you have the following #defines Hold it right there. You're causing yourself problems you don't need by doing it this way. Definitions of macros used to control build features of the code don't belong into the source code itself. Once they're in there, they're needlessly hard to get out again, as you're just finding out. I would strongly suggest you use flags passed to the compiler on its invocation instead (-DDEBUG=1 etc., for most C compilers). That way, they'll be plainly visible to you in the make run's screen output (and in the .lst file, too). The visible hint won't be quite as wordy as your #message, but it's right there in front of your eyes. In uV2 you would use multiple targets in the same project, using the same set of source files, but with different flags each, to achieve the same effect.