不是一个真正的问题,而是一个好奇心,更多的是我不想要一些愚蠢的问题,重点是玩Visual Studio(x64),我注意到如果一个结构存在一个wchar *
#include <iostream>
struct {
wchar_t* pTest;
unsigned int uTest;
} Test;
int main()
{
std::cout << "sizeof(Test) - " << sizeof(Test) << "\n\n";
}
sizeof(测试) - 16 http://cpp.sh/3lbg不一定是12?
#include <iostream>
struct {
wchar_t* pTest;
//unsigned int uTest;
} Test;
int main()
{
std::cout << "sizeof(Test) - " << sizeof(Test) << "\n\n";
}
sizeof(测试) - 8 http://cpp.sh/4bld
#include <iostream>
struct {
//wchar_t* pTest;
unsigned int uTest;
} Test;
int main()
{
std::cout << "sizeof(Test) - " << sizeof(Test) << "\n\n";
}
sizeof(测试) - 4 http://cpp.sh/7xwjl
我理解那背后有一个逻辑,但我对与此有关的规则是谁感到困惑。