如果展开宏,您可以看到它为什么不能按预期工作:
#if ((GpioRegs *) (GPIO_BASE + 0x04)) == ((GpioRegs *) (GPIO_BASE + 0x04))
AFAIK,你不能在里面做类型转换
#if
。您可能需要制作一组不同的宏,解析为整数而不是指针,例如:
gpios.h:
#define GPIO_BASE 0x08000100
#define GPIOA_INT (GPIO_BASE + 0x04)
#define GPIOB_INT (GPIO_BASE + 0x0C)
#define GPIOC_INT (GPIO_BASE + 0x14)
#define GPIOA ((GpioRegs *) GPIOA_INT)
#define GPIOB ((GpioRegs *) GPIOB_INT)
#define GPIOC ((GpioRegs *) GPIOC_INT)
开关.h:
#define SWITCH1_PORT_INT GPIOA_INT
#define SWITCH2_PORT_INT GPIOA_INT
#define SWITCH1_PORT GPIOA
#define SWITCH2_PORT GPIOA
开关。c:
#if SWITCH1_PORT_INT == SWITCH2_PORT_INT
// Code is a lot simpler if both switches are on the same port
#else
// Otherwise do it the hard way
#endif