在使用 Atmel SAM3X8E 处理嵌入式系统项目时,我注意到一些 CMSIS 头文件中有以下代码。
#ifndef __cplusplus
typedef volatile const uint32_t RoReg; /**< Read only 32-bit register (volatile const unsigned int) */
#else
typedef volatile uint32_t RoReg; /**< Read only 32-bit register (volatile const unsigned int) */
#endif
为什么 C++ 的 typedef 不包括const
?我在某处看到提到 C++ 不在运行时内存中存储整数 const 变量,如果为真则意味着const
由于微控制器寄存器的内存映射方式需要删除,但我似乎找不到任何其他说明C++ 做到了(尽管我的搜索确实很简短)。对 C++ 没有太多经验,我还认为可能是 C++ 不允许const
结构成员,因为这些类型定义主要用于结构类型定义中用于寄存器集合,但似乎也并非如此。