Miki Tebeka <mi*********@zoran.com> wrote:
Hello All,
Out assembly code have the following syntax:
move #2, d1;
How can I write a macro that will produce the above line?
If I try:
#define mv(reg) move #2, reg;
In definitions of function-like macros # and ## are operators.
I get (for cpp -E):
f:1:23: '#' is not followed by a macro parameter
I've tried with ## and \# but it doesn't work.
Is there a way around this?
Try this:
#define HASH2 #2
#define mv(reg) move HASH2, reg;
[Note:
If you're thinking of producing "#2" by pasting "#" and "2", then
this will never work, because "#2" is not a valid token:
#define HASH #
#define xcat(a, b) a ## b
#define cat(a, b) xcat(a, b)
#define mv_dest(n, reg) move cat(HASH, n), reg;
mv_dest(2, d1)
testcpp:11:7: pasting "#" and "2" does not give a valid preprocessing token
You can always do it like this (you have to pass "#2" as argument):
#define mv_dest(dest, reg) move dest, reg;
mv_dest(#2, d1)
]
C preprocessor is *not* a text processor, and might prove unsuitable
for your task. My advice would be rather stay with your in-house
solution, or look for a regular text processor (many would point to m4).
--
Stan Tobias
sed 's/[A-Z]//g' to email