ezviagintcev
ezviagintcev

Reputation: 107

Define function in macros (in C)

I need to #define a macros as a function. For example:

#define REGISTER 0x80000000
...
writel(addr, nic->regs + REGISTER); // arguments are address and register

I defined it like that:

#define WRITEL(addr, nic->reg + reg) ((writel(addr, nic->regs + (reg))))

What's wrong here? Thanks

Upvotes: 0

Views: 153

Answers (1)

JeremyP
JeremyP

Reputation: 86651

Macro arguments are a bit like normal function arguments. On the left side you just need a name that is used on the right

 #define WRITEL(ADDR, REG) (writel(ADDR, nic->regs + (REG)))

Upvotes: 7

Related Questions