gpt4 book ai didi

c#define 宏字符串连接

转载 作者:太空宇宙 更新时间:2023-11-04 03:23:40 26 4
gpt4 key购买 nike

Win7 SP1 32 位,Code Composer Studio v6.1(我认为他们使用的是 gcc)

我似乎在让魔术序列执行以下操作时遇到了一些麻烦......

我想编写一个预处理器#define 指令,格式如下:

(伪代码)

#define extn(x) extern   uint16_t    str_#x

然后使用它,因此:

extn(hello);

然后经过预处理,结果看起来像...

extern uint16_t  str_hello;

维基百科中的这篇文章 C preprocessor 状态:

"You cannot combine a macro argument with additional text and stringify it all together. You can however write a series of adjacent string constants and stringified arguments: the C compiler will then combine all the adjacent string constants into one long string."

最佳答案

您想要的是连接,而不是字符串化。因此,使用 ##:

#define extn(x) extern   uint16_t    str_##x

关于c#define 宏字符串连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43175986/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com