Macro that expand differently depending on the function calling it.



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.

Is there any way to handle that while still keeping a generic include
file ?

Thanks

-- Fabrice

PS: If you think this is off-topic because I mention mips16 and thumb,
dont even bother replying.I think the C standard was designed to cope
with implementation specific extensions and issues like this.

.



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)
  • Re: HELP!? Passwords are driving me crazy.
    ... question happen on opening before ... But if I understand your setup; you have 5 source files from maybe 5 ... have to protect it with a password. ... macro in those can do that. ...
    (microsoft.public.excel.worksheet.functions)
  • Field Changing Macro
    ... Someone gave me a macro named ResetLinkPath for use in resetting hyperlinks. ... since it eliminates the prompt to select the path to the source. ... files that are all in a common folder other than the folder in which the ... You could use this option if there are multiple source files that were ...
    (microsoft.public.word.vba.general)
  • Preprocesor problem
    ... I want to use unique numbers in the source files and I want to impose a ... numbers are like code locators and from a debug log with this number; ... expected macro formal parameter when I compile. ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • Macros: Step Thru Works, Run Works, Keyboard Shortcut Locks up
    ... all macros and source files, ... By chance I tried Macro RUN, and lo an behold, it worked. ... Dim DestBook As Workbook ...
    (microsoft.public.excel.programming)