Я хочу сделать статик инициализацию переменной BSTR. макрос:
должен раскрываться в :
Код | static const struct { unsigned int nbytes; wchar_t chars[4]; } mybstr = { 3, { 'a', 'b', 'c', 0 } };
|
sizeof(L"abc")/2 не катит - не стандарт. Я думаю, что что-то похожее можно сделать с помощью boost PP SET, правда я в нём не разбираюсь.
Код | #include "stdafx.h"
#include <stdio.h>
#include <boost/preprocessor/seq/size.hpp> #include <boost/preprocessor/seq/enum.hpp>
#define BSTR_DEF(varname, str_seq) \ struct { \ unsigned int nbytes; \ wchar_t chars[BOOST_PP_SEQ_SIZE(str_seq)+1]; \ } varname = { BOOST_PP_SEQ_SIZE(str_seq), { BOOST_PP_SEQ_ENUM(str_seq), 0 } }
static const BSTR_DEF(mybstr, ('a')('b')('c'));
int main() { printf("%d %d %S\n", mybstr.nbytes, sizeof(mybstr.chars)/2, mybstr.chars); return 0; }
|
|