我怎么可以将解析令牌的C宏转换为D?如何将解析令牌的C宏转换为D?
# define _SIZEOF(x) sz_##x
# define SIZEOF(x) _SIZEOF(x)
# define NEXTPTR(p,t) (((char *) p) + SIZEOF(t))
感谢
我怎么可以将解析令牌的C宏转换为D?如何将解析令牌的C宏转换为D?
# define _SIZEOF(x) sz_##x
# define SIZEOF(x) _SIZEOF(x)
# define NEXTPTR(p,t) (((char *) p) + SIZEOF(t))
感谢
哇。这是一个黑客。
cast(void*) p + sz_[whichever]
,我会说?只需手动展开即可。
或建立编译时查找表... – vines 2012-01-17 00:00:25
使用示例:BYTE eventdata [SIZEOF(xEvent)]; xEvent它是struct xEvent {} – bioinfornatics 2012-01-17 14:40:05
template SIZEOF(T) {
static if (is(T == char))
enum SIZEOF = sz_char;
else static if (is(T == ...))
...
}
T* NEXTPTR(T)(p) {
return (((char *) p) + SIZEOF!t)
}
与'#define NEXTPTR(p,t)((char *)(((t *)p)+1))'(如果'sz_'前缀与'sizeof'相同) – 2012-01-15 17:16:52
使用'sz_'前缀让我觉得它和'sizeof'不一样。 :( – FeepingCreature 2012-01-16 09:52:32