Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想缩短变量名,所以不要这样:FPData.Temps.T.Solar.Val
我想使用:
TEMP_Solar.Val
并定义宏:
#define TEMP_ FPData.Temps.T.
但它只有在我在两者之间放置空间时才有效:
TEMP_ Solar.Val
编译好,但我想用这个
可能的?我知道我可以通过使用宏和参数“TEMP_VAL(Solar)”来解决问题,但希望保持简单,线性连接......
这是因为处理宏的预处理器只识别它们自己的标识符。例如,当您使用它时TEMP_Solar,它与TEMP_.
TEMP_Solar
TEMP_
预处理器甚至可以使用简单strcmp的方法来查找它的宏,因此不能没有子字符串,也不能有大小写差异。
strcmp
最明显和最简单的解决方案:
#define TEMP FPData.Temps.T TEMP.Solar.Val
(您不能也不应该更改结构成员的实际变量名称。)