vc一些預先處理)

來源:互聯網
上載者:User
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基本和前面那個選擇編譯一樣的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.