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 All. Imagine a function that looks like this:
DEFINED_SYMBOL1 type FnName(args) DEFINED_SYMBOL2 { ...; }
type FnName(args) { ...; }
#pragma NOAREGS type FnName(args) reentrant { ...; }
#define DEFINED_SYMBOL2
>#define DEFINED_SYMBOL2 reentrant
#define DEFINED_SYMBOL1 #pragma NOAREGS
How about:
#if defined( USE_REENTRANT ) // Use the Keil C51 'reentrant' extended keyword #define REENTRANT reentrant #else // Do not use 'reentrant' - the expansion is nothing! #define REENTRANT #endif #if defined( USE_NOAREGS ) // The NOAREGS Compiler Option has been requested #pragma NOAREGS #endif type FnName(args) REENTRANT { ...; }
One C rule you must obey is that you can't have a pre-proc. directive in a pre-proc. directive. E.g.
#define ILLEGAL #pragma
#define STRINGER(x) #x #define STRING_CAT(x, y) STRINGER(x) ## STRINGER(y)
Hi Guys. Thanks for the replies. The method I'm now using is like what Andrew suggested, but taken one step further because we try to avoid having any compiler-specific code in our *.c source files. How do we do that? Well, the reentrant stuff is easy because it's a keyword. For the pragmas, we conditionally include a file just prior to the function of interest. In that file, if the compiler is C51 AND that particular function is the one we're interested in AND it needs the pragma (all based on values of defined symbols), then the pragma is all that comes out of that file. And we undo the pragma after the file ... With this "include-file method" we're able to keep the *.c source files reasonably legible ... Regards, Andrew
"we try to avoid having any compiler-specific code in our *.c source files. " Excellent! "For the pragmas, we conditionally include a file..." That sounds clever - I'll bear it in mind if I need to do such a thing.