How to conditionally NOAREG a fn?

Hi All.

Imagine a function that looks like this:

DEFINED_SYMBOL1
type FnName(args) DEFINED_SYMBOL2
{
 ...;
}
By appropriate definition of DEFINED_SYMBOL1 and DEFINED_SYMBOL2, I would like to end up with:
type FnName(args)
{
 ...;
}
or
#pragma NOAREGS
type FnName(args) reentrant
{
 ...;
}
The DEFINED_SYMBOL2 part is really easy, either
#define DEFINED_SYMBOL2
or
>#define DEFINED_SYMBOL2 reentrant
But the DEFINED_SYMBOL1 isn't so easy, because C51 won't allow me to
#define DEFINED_SYMBOL1 #pragma NOAREGS
("misused # operator"). So how should I proceed?

BTW, the source file has multiple functuons in it, so compiling with NAREGS on the command line is not an option.

Thanks,

Parents
  • 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
    {
     ...;
    }
    Where your predefined symbols are USE_REENTRANT and USE_NOAREGS

    NB: The USE_REENTRANT techniques illustrates a good way to "isolate" all your compiler-dependencies - just use __C51__ as your predefined symbol

Reply
  • 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
    {
     ...;
    }
    Where your predefined symbols are USE_REENTRANT and USE_NOAREGS

    NB: The USE_REENTRANT techniques illustrates a good way to "isolate" all your compiler-dependencies - just use __C51__ as your predefined symbol

Children
More questions in this forum