Windows核心編程:第13章 內存體系結構

Github

https://github.com/gongluck/Windows-Core-Program.gitc++

//第13章 內存體系結構.cpp: 定義應用程序的入口點。
//

#include "stdafx.h"
#include "第13章 內存體系結構.h"

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPWSTR    lpCmdLine,
    _In_ int       nCmdShow)
{
    WORD w;
    PVOID test = &w;
    char c = *(PBYTE)test;

    //訪問錯位數據
    test = (PBYTE)&w + 1;
    DWORD d = *(UNALIGNED PDWORD)test;//UNALIGNED在x86平臺無效

    if ((int)&d % sizeof(d) == 0)
        OutputDebugString(TEXT("***********對齊***********\n"));
    else
        OutputDebugString(TEXT("***********未對齊***********\n"));

    system("pause");
    return 0;
}
相關文章
相關標籤/搜索