C 宏编写堆栈变长结构?

发布于 2024-10-12 10:13:44 字数 294 浏览 4 评论 0原文

我不知道这是否可行,但我想写一个宏 在堆栈上声明一个可变长度结构。我想做这样的事情:

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦情居士 2024-10-19 10:13:44

您可以做类似的事情,但是您需要一些东西来避免具有相同冲突名称的结构。

#define STATICLIST(max) struct { int iSize; id iObjects[max]; }

这应该可以做到。

You could do something like that, but you'll need something in order to avoid structs with the same conflicting name.

#define STATICLIST(max) struct { int iSize; id iObjects[max]; }

this should do it.

时间你老了 2024-10-19 10:13:44

您可以使用标记粘贴操作 ## 将大小包含在结构名称中:

#define STATICLIST(max)       struct SStaticList##max { int iSize; int iObjects[max]; }

You could use the token pasting operation ## to include the size in the structure name:

#define STATICLIST(max)       struct SStaticList##max { int iSize; int iObjects[max]; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文