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.
I have created a very useful macro that will have disastrous results if it is used inside an ISR. A few years from now some unsuspecting soul (who could be me) will probably use it inside an ISR and spend days debugging. Is there a means of:
#if ISR tell the clown this is bad #endif
IMHO, not worth it. 'Inside ISR' could also mean 'inside a function called from an ISR and from normal code as well'. How do you detect that? I think all you need to do is write a comment next to the macro definition saying 'DON'T EVEN THINK ABOUT USING THIS MACRO IN AN ISR'. After all, isn't part of the philosophy of C 'if you don't know what you are doing, you are in trouble'? - mike
After all, isn't part of the philosophy of C 'if you don't know what you are doing, you are in trouble' Absolutotally agree, I have, however, who knows how often, found things like the above being the cause of wasted time. One reason, of course, is that when emulating you do not see the innards of a macro. If macro code and comments were shown my question would be irrelevant since the very first glance in the debugger would tell the story. Another reason for my statement is that the reason I have found most often for 'mysterious behaviour' indeed is such a mistake. My basic philosophy is to do everything possible to help the poor sod that has to do a "small enhancement" (we all know what that means) to my code after I have moved to other things. Erik
About the only feasible method I see would be to use something like NOT_IN_ISR or so as part of the macro's name.
I guess you could bracket all your ISR functions between:
#define ISR
#undef ISR
#ifdef ISR #error tell the clown this is bad #endif