[問題] 有沒有辦法知道目前的 ALIGNMENT 是多少?
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#pragma pack(4)
#define ALIGNMENT <<<< 這裡該寫甚麼呢
#pragma pack()
using namespace std;
int main(int argc, char * argv[])
{
cout << ALIGNMENT << endl;
system("pause");
return EXIT_SUCCESS;
}
補充說明(Supplement):
請不要說直接寫4 wwwwwwww
因為有的時候 #pragma pack() 的設定遠在天邊 想知道有沒有辦法抓出來
補充一下 我只會這個算法
#include <iostream>
#pragma pack(push)
#pragma pack(4) //1,2,4,8 OK
typedef struct _Test_Pad //but 16 don't work
{
char Reserve;
__int64 Pad;
} Test_Pad;
#define ALIGNMENT (unsigned int)(&(((Test_Pad *) 0)->Pad))
#pragma pack(pop)
using namespace std;
int main(int argc, char * argv[])
{
cout << ALIGNMENT << endl;
system("pause");
return EXIT_SUCCESS;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.86.6
※ 編輯: chrisdar 來自: 123.195.86.6 (02/18 00:26)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):