1)
#if defined XXX_XXX
#endif
是條件編譯,是根據你是否定義了XXX_XXX這個宏,而使用不同的代碼。
一般.h檔案裡最外層的
#if !defined XXX_XXX
#define XXX_XXX
#endif
是為了防止這個.h標頭檔被重複include。
#undef為解除定義,#ifndef是if not defined的縮寫,即如果沒有定義。
2)
#error XXXX
是用來產生編譯時間錯誤資訊XXXX的,一般用在預先處理過程中;
例子:
#if !defined(__cplusplus)
#error C++ compiler required.
#endif
3)
extern 全域變數 相當於C#中的public
4)
__cdecl和__stdcall是兩種C++函數調用規則的系統約定。
__cdecl的:
Argument-passing order
Right to left
Stack-maintenance responsibility
Calling function pops the arguments from the stack
Name-decoration convention
Underscore character (_) is prefixed to names, except when exporting __cdecl functions that use C linkage.
Case-translation convention
No case translation
__stdcall的:
Argument-passing order
Right to left.
Argument-passing convention
By value, unless a pointer or reference type is passed.
Stack-maintenance responsibility
Called function pops its own arguments from the stack.
Name-decoration convention
An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func@12
Case-translation convention
None
5)
#pragma pack( [ show ] | [ push | pop ] [, identifier ] , n )
這個是用來指定類、結構的記憶體對齊的;
這個說起來有點多,你上網查記憶體對齊能查到;
6)
__declspec( dllimport ) declarator
__declspec( dllexport ) declarator
這兩個是與Dll有關的,聲明可以從dll檔案中輸出和輸入的函數、類或資料;
7)
#pragma once
是規定當編譯時間這個檔案只能被include一次;
類似
#if define
8)
disable message
才疏學淺,沒見過。。。。
9)
__int64
是64位的整數類型,是為了防止32位的int不夠用時用的;
10)
#pragma code_seg( [ [ { push | pop}, ] [ identifier, ] ] [ "segment-name" [, "segment-class" ] )
是用來定義函數被放置在obj檔案的哪個段裡。
---------------------------------------------------
#if defined MACRO_NAME
與
#ifdef MACRO_NAME 還是稍微有點區別的。
譬如我們公司就鼓勵寫第一種,因為它可以這麼寫:
#if defined(MACRO_NAME) && defined(MACRO_NAME)
這個#error是可以讓使用者在編譯時間手動產生一個編譯錯誤,更準確的說是在預先處理的時候。
#if !defined(__cplusplus)
#error C++ compiler required.
#endif
這個就是說如果你的程式不是C++的,譬如C的,就會報錯。裡面的錯誤資訊是使用者自己決定的。
#pragma once基本和前面那個選擇編譯一樣的。