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
"Does anyone here ever use #message in other compilers?" I kind of doubt it, since it is not part of Standard C.
Thanks for the response. I realize it is not in the kernigan richie book, but I have seen it in other compilers and other books. It can be useful, though I understand that if someone did not know it existed, they would not use it. For and example of its use, if you want to test the version of something and do different things based on what you find in a header, then you print a message as some you may want to reserve warnings for things people really should take care of. What are your thoughts?
its simple #ifdef I_WANT_AN_ERROR_MESSAGE I screwed up #endif Will work just fine Erik
"What are your thoughts?" My thoughts are to not use facilities or extensions that are not part of the standard language unless there is absolutely no other way to accomplish a task. Since Standard C lacks a facility for echoing anything other than error messages (using #error), I echo build variation messages to a user using the command shell. I specify what I want to build to the make tool, which then passes the appropriate macro values to the compiler (subsequently choosing appropriate values and conditional compile paths in the C source and header files) and uses the shell for echoing messages telling the user what it's doing.
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.
I may be naive, but that sounds like you are not using MicroVision2. If you want to use the ide, then I think what you suggest may be complicated (could be wrong on this though)
"If you want to use the ide, then I think what you suggest may be complicated" Although I haven't actually tried it, I think it should be quite easy using the Custom Translation facility...?
View all questions in Keil forum