我怎麼可以將解析令牌的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