您是否不能像从特定名称空间调用函数那样,从特定名称空间调用预处理器宏?

问题描述

好吧,所以我正在研究一些嵌入式代码,以便在msp430启动板上运行,我试图将引脚切换到高电平,当我开始尝试使用头文件中的一个宏时,我遇到了一个问题也位于main.cpp文件中的特定名称空间中。我假设我可以使用与上述约定相同的约定来调用名称空间中的函数调用宏?在我声明使用名称空间而不是msp430 ::之前,我不会编译代码,因为我在头文件中有3个不同的名称空间。有没有没有声明使用命名空间的方法吗?我也可以使用命名空间中的变量来做到这一点,所以我看不到使用简单的宏定义无法实现的事情。

expected unqualified-id before token

//section from the header file
#define P4DIR_m  *((unsigned int volatile*)0x0224u)
#define P8OUT_m  *((unsigned int volatile*)0x0262u)
#define P8DIR_m  *((unsigned int volatile*)0x0264u)
#define P1DIR_m  *((unsigned int volatile*)0x0204u)
#define LEDOUT_m *((unsigned int volatile*)0x0202u) //this line gives the error

 
//----------main.cpp

//code that called the macro orginally
msp430::LEDOUT_m |= 0x01; //this Failed 

//new code
using namespace msp430;

LEDOUT_m |= 0x01; // this worked but I don't want to do this as I have other namespaces

ide snapshot with code

解决方法

否,宏不知道名称空间。尽可能避免使用宏。在这里您可能可以做类似的事情

strlen

https://godbolt.org/z/1j7e3f