M
Mark Odell
I've read the FAQ and I still can't see how to get what I want. Here's
what I'd like to do:
I have a list of register numbers that the CPU's instruction set
requires be literal constants, e.g.
#define DMA_CR0 0x100
#define DMA_CR1 0x108
#define DMA_CR2 0x110
#define DMA_CR3 0x118
I'd like to call another function with a one of these but make it
indexed like
dmaCr = dmaRdCr(channel); /* where channel = [0,..,3] */
and, logically, dmaRdCr() is implemented like this:
dmaRdCr(DMA_MAKE_REG_NUM(DMA_CR, channel);
I've got DMA_MAKE_REG_NUM defined as:
#define DMA_MAKE_REG_NUM(reg, ch) (ch == DMA_CHAN_0 ? reg##0 : \
ch == DMA_CHAN_1 ? reg##1 : \
ch == DMA_CHAN_2 ? reg##2 : \
ch == DMA_CHAN_3 ? reg##3 : -1)
But the compiler is unhappy with this. Is there a simpler way? Do I
simply have a substitution error?
Thanks,
what I'd like to do:
I have a list of register numbers that the CPU's instruction set
requires be literal constants, e.g.
#define DMA_CR0 0x100
#define DMA_CR1 0x108
#define DMA_CR2 0x110
#define DMA_CR3 0x118
I'd like to call another function with a one of these but make it
indexed like
dmaCr = dmaRdCr(channel); /* where channel = [0,..,3] */
and, logically, dmaRdCr() is implemented like this:
dmaRdCr(DMA_MAKE_REG_NUM(DMA_CR, channel);
I've got DMA_MAKE_REG_NUM defined as:
#define DMA_MAKE_REG_NUM(reg, ch) (ch == DMA_CHAN_0 ? reg##0 : \
ch == DMA_CHAN_1 ? reg##1 : \
ch == DMA_CHAN_2 ? reg##2 : \
ch == DMA_CHAN_3 ? reg##3 : -1)
But the compiler is unhappy with this. Is there a simpler way? Do I
simply have a substitution error?
Thanks,