Re: [問題] 有沒有辦法知道目前的 ALIGNMENT 是多少?
※ 引述《chrisdar (克里斯)》之銘言:
: 開發平台(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))
^^^
痾 不好意思 ,之前在版上有看過這樣的寫法和解說
但現在都忘了
想再請教一下那個0 是甚麼特別的用法意思
感恩m(_ _)m
: #pragma pack(pop)
: using namespace std;
: int main(int argc, char * argv[])
: {
: cout << ALIGNMENT << endl;
: system("pause");
: return EXIT_SUCCESS;
: }
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 124.8.128.190
推
02/18 03:19, , 1F
02/18 03:19, 1F
→
02/18 03:19, , 2F
02/18 03:19, 2F
推
02/18 09:24, , 3F
02/18 09:24, 3F
→
02/18 09:25, , 4F
02/18 09:25, 4F
→
02/18 14:32, , 5F
02/18 14:32, 5F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):