Hung Ho
Hung Ho

Reputation: 11

Macro argument is not expanded instead gives compiler error - c preprocessor

/* file.c */

#define PCH_LPC_RCBA_BASE_ADDRESS           0xFED1C000
#define READ_MEM8 (MemAddr)                 MmioRead8 (MemAddr)
#define READ_MEM8_RCRB (wReg)               READ_MEM8 (PCH_LPC_RCBA_BASE_ADDRESS | wReg)


UINT8 IoValue = READ_MEM8_RCRB (0x10);

Got a compiler error error C2065: 'wReg' : undeclared identifier

wReg did not get substituted with 0x10. what did I do wrong?

Upvotes: 0

Views: 134

Answers (2)

akhileshmoghe
akhileshmoghe

Reputation: 643

It's a standard Rule not to leave blank between Macro Template and It's Argument. Do not give space between READ_MEM8_RCRB and (wReg) as:

  1. wReg will be part of Macro Expansion.
  2. It may result in Improper Result or in your case Compile Time Error.

Upvotes: 2

Ed Heal
Ed Heal

Reputation: 60037

Remove the space

i.e.

#define PCH_LPC_RCBA_BASE_ADDRESS           0xFED1C000
#define READ_MEM8(MemAddr)                 MmioRead8 (MemAddr)
#define READ_MEM8_RCRB(wReg)               READ_MEM8(PCH_LPC_RCBA_BASE_ADDRESS | wReg)

Upvotes: 0

Related Questions