开发者

C Macro to write a stack variable length struct?

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:

S开发者_JAVA百科TATICLIST(32) Size32List
STATICLIST(64) Size64List

But I'm getting redeclaration of the type struct SStaticList errors


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.


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]; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜