英文:
How to align memory address of Windows x64 C++ global variable
问题
我希望我创建的全局变量的地址是0x1000的倍数。
示例
char alignstr[0x100] = "this is align string";
int main()
{
printf("var address = [%p]", &alignstr);
}
输出
"var address = [0x140005000]"
英文:
I want the address of the global variable I create to be a multiple of 0x1000.
sample
char alignstr[0x100] = "this is align string";
int main()
{
printf("var address = [%p]", &alignstr);
}
output
"var address = [0x140005000]"
答案1
得分: 2
只使用 alignas
:
alignas(0x1000) char alignstr[0x100] = "this is align string";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论