C 宏编写堆栈变长结构?
我不知道这是否可行,但我想写一个宏 在堆栈上声明一个可变长度结构。我想做这样的事情:
#define STATICLIST(max) struct SStaticList { int iSize; id iObjects[max]; }
并像这样调用它:
STATICLIST(32) Size32List
STATICLIST(64) Size64List
但我收到类型 struct SStaticList 错误的重新声明
I don't know if this is possible but I'd like to write a macro that
declare a variable length struct on the stack. I want to do something like this:
#define STATICLIST(max) struct SStaticList { int iSize; id iObjects[max]; }
and the call it like this:
STATICLIST(32) Size32List
STATICLIST(64) Size64List
But I'm getting redeclaration of the type struct SStaticList errors
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以做类似的事情,但是您需要一些东西来避免具有相同冲突名称的结构。
这应该可以做到。
You could do something like that, but you'll need something in order to avoid structs with the same conflicting name.
this should do it.
您可以使用标记粘贴操作 ## 将大小包含在结构名称中:
You could use the token pasting operation ## to include the size in the structure name: