What is the meaning of this C++ macro? -
i can't figure out macro means:
#define declare_handle(n) typedef struct n##__{int i;}*n declare_handle(hwnd);
i have learned c program that:
"##" means connect parameter.
so macro equals:
typedef struct hwnd__{int i;}*hwnd
is right?
if right, meaning of sentence?
==================
code game bombermaaan (for windows , linux),
link http://sourceforge.net/p/bombermaaan/code/head/tree/trunk/src/bombermaaan/winreplace.h,
line no 90.
the main purpose of construct prevent misuse of handles. if handles void *
or int
or long long
or other basic type, there nothing prevent using 1 instead of another. pointer struct hwnd__
, pointer struct hbitmap__
isn't same thing, if have following code:
hwnd hwnd; hbitmap hbmp; hbmp = getbitmap(...); hwnd = hbmp; // gives compiler error.
it's classic technique ensure unique types api supplier don't want provide true declaration for. although i'm not entirely sure why need proper struct declaration, away with:
#define declare_handle(n) struct n ## __; struct n ## __ *n;
that ensure dereferece hwnd won't possible, since compiler object "use of incomplete type".
Comments
Post a Comment