DECLARE HANDLE巨集解析

2021-08-10 15:12:53 字數 654 閱讀 5681

在mfc原始碼中,經常看到這樣的語句:

declare_handle(hdrvr);

declare_handle(hdtrcv);

檢視declare_handle定義如下:

#ifdef strict

typedef void *handle;

#define declare_handle(name) \

struct name##__ ;\

typedef struct name##__ *name\

#else

typedef pvoid handle;

#define declare_handle(name) typedef handle name

#endif

預設情況下,vc/vs是開啟strict的,在這種情況下相當於先定義了乙個結構:

struct name##__

typedef struct name##__ *name其實就相當於定義了乙個指向結構體name__的指標型別name。

在非strict的情況下,定義name 為handle型別。其實handle 也是乙個指標型別。

則declare_handle(hdrvr);declare_handle(hdtrcv);是宣告hdrvr和hdtrcv 為乙個指標型別。

define 巨集 替代巨集

編寫 時經常要定義常量 static const nstimeinterval kanimationduration 0.3 複製 使用型別變數,可以清楚地描述常量的含義,以及它的型別。命名法 若常量侷限於某 編譯單元 translation unit,也就是實現檔案,m檔案 之內,則在前面加字母k...

define 巨集 替代巨集

編寫 時經常要定義常量 static const nstimeinterval kanimationduration 0.3 複製 使用型別變數,可以清楚地描述常量的含義,以及它的型別。命名法 若常量侷限於某 編譯單元 translation unit,也就是實現檔案,m檔案 之內,則在前面加字母k...

abs int 巨集定義 巨集定義和巨集方法

巨集定義和巨集方法 定義機型 define is iphone5 uiscreen instancesrespondtoselector selector currentmode cgsizeequaltosize cgsizemake 640,1136 uiscreen mainscreen cu...