Re: Macro that expand differently depending on the function calling it.



Fabrice wrote:
Hi,

Lets say I want to define a generic macro to swap bytes in a integer:
#define swapbytes(x) ...
I have several implementation of the macros, one is generic C, the
other one will be an optimized assembly version for a specific
architecture.

So I do something like that in swapbytes.h:

#ifdef __SOME_IMPLEMENTATION_SPECIFIC_MACRO__
#define swapbytes(x) \
... some implementation defined assembly crap...
#else
#define swapbytes(x) \
... some generic C code ...
#endif

This works well and I can extend this to support many different
implementation dependent optimizations: MIPS, ARM, x86,...

Now i have an additional issue. In some case, I have two functions in
the same source files that requires two different implementations of
the macro. An example of such case is when you deal with arm thumb or
mips16 instruction set. Some implementation allows you to mix both
types of code, but my swapbytes macro would needs to be different for
both of them.

Why not just uses another macro, or better still, functions?

--
Ian Collins.
.



Relevant Pages

  • Re: Macro that expand differently depending on the function calling it.
    ... Lets say I want to define a generic macro to swap bytes in a integer: ... the same source files that requires two different implementations of ... An example of such case is when you deal with arm thumb or ... mips16 instruction set. ...
    (comp.lang.c)
  • Macro that expand differently depending on the function calling it.
    ... Lets say I want to define a generic macro to swap bytes in a integer: ... the same source files that requires two different implementations of ... An example of such case is when you deal with arm thumb or ... mips16 instruction set. ...
    (comp.lang.c)
  • Re: plz analyze the o/p ?
    ... The declaration "void main" is wrong; ... The header, and the clrscrand getch() functions, are ... you need to keep in mind that macro ... swap macro isn't. ...
    (comp.lang.c)
  • Re: derangement: coding review request
    ... "Michael Mair"> ... > Dan Pop wrote: ... >> No point in complicating the interface of SWAP. ... >> Read the FAQ to see why this is not a good macro definition. ...
    (comp.lang.c)
  • Re: derangement: coding review request
    ... >Dan Pop wrote: ... Using a macro without understanding its needs and limitations is just ... >> No point in complicating the interface of SWAP. ... bother writing a prototype definition when there are no parameters. ...
    (comp.lang.c)