2012-01-15 53 views
1

我怎麼可以將解析令牌的C宏轉換爲D?如何將解析令牌的C宏轉換爲D?

# define _SIZEOF(x) sz_##x 
# define SIZEOF(x) _SIZEOF(x) 
# define NEXTPTR(p,t) (((char *) p) + SIZEOF(t)) 

感謝

+2

與'#define NEXTPTR(p,t)((char *)(((t *)p)+1))'(如果'sz_'前綴與'sizeof'相同) – 2012-01-15 17:16:52

+1

使用'sz_'前綴讓我覺得它和'sizeof'不一樣。 :( – FeepingCreature 2012-01-16 09:52:32

回答

1

哇。這是一個黑客。

cast(void*) p + sz_[whichever],我會說?只需手動展開即可。

+0

或建立編譯時查找表... – vines 2012-01-17 00:00:25

+0

使用示例:BYTE eventdata [SIZEOF(xEvent)]; xEvent它是struct xEvent {} – bioinfornatics 2012-01-17 14:40:05

0
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) 
}