我有一个问题。我正在尝试通过先前定义的常量添加结构元素。 这是示例代码(OpenGL+WinAPI)
#define ENGINE_STRUCT \
HGLRC RenderingContext;\
HDC DeviceContext;
然后:
typedef struct SWINDOW {
ENGINE_STRUCT
HWND Handle;
HINSTANCE Instance;
CHAR* ClassName;
BOOL Fullscreen;
BOOL Active;
MSG Message;
} WINDOW;
这可能吗?
最佳答案
是的,这是可能的,宏是一个简单的文本替换
http://www.cplusplus.com/doc/tutorial/preprocessor/
The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements.
关于c - 通过定义向结构体添加元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23968396/