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



On Wed, 31 Oct 2007 00:53:34 -0000, Fabrice
<fabrice.gautier@xxxxxxxxx> wrote in comp.lang.c:

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.

If you can provide proof from an Internationally recognized court of
law that has granted you supreme dictatorial powers over comp.lang.c,
and furthermore provide proof of that court's legal jurisdiction in
doing so, then you might attempt to forbid people who might dislike
your off-topic question from replying.

But I doubt if that would stop them. It certainly wouldn't stop me.

As for your incorrect belief about the C standard, and it is
incorrect, who gives a piece of bovine excrement?

*plonk*

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: Want to highlight misspelled words, OR ... easily see correct word
    ... I was not proposing a macro to find correct or incorrect spelling in the ... The OP indicated that EXCEL is used to sort the wheat from the chaff ... The macro Graham posted probably meets the OP's need. ... nothing will be marked as incorrect because it's all single letters). ...
    (microsoft.public.word.docmanagement)
  • RE: Help with creating a Macro
    ... I was looking back over my original message and I ... If you are trying to compute units per hour then your formula is incorrect. ... I feel a macro would be the most accurate and efficient ... Most of the order data are on multiple rows. ...
    (microsoft.public.excel.misc)
  • Re: Want to highlight misspelled words, OR ... easily see correct word
    ... I see now that the macro is designed to operate on results rather than the matrix. ... I guess I hadn't read enough of the original post to realize that the OP had already extracted all the possible words. ... I was not proposing a macro to find correct or incorrect spelling in the matrix. ... nothing will be marked as incorrect because it's all single letters). ...
    (microsoft.public.word.docmanagement)
  • Re: tolower macro
    ... tolower() goes into a lookup table or some more sophisticated ... It replaces the placeholder argument of the macro definition ... They *could* be optimized if the compiler chooses to do so. ... It would be, for first, incorrect. ...
    (comp.lang.c.moderated)
  • Re: Syntactic Abstraction under the New Model
    ... But that's also incorrect, for pretty much the same reasons, and essentially boils down to lack of experience. ... We then have the obvious problem of capturing, but in DEFMACRO, this can be somewhat intercepted by using generated names and carefully working with the macro. ... there is also the issue of "Referential Transparency" identified in the same paper referenced above. ...
    (comp.lang.scheme)