c - 通过定义向结构体添加元素

标签 c winapi opengl struct c-preprocessor

我有一个问题。我正在尝试通过先前定义的常量添加结构元素。 这是示例代码(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/

相关文章:

exception - 为什么按下numlock会使OCaml opengl程序崩溃?

c - 短类型可以在 C 中存储的最大和最小数字是多少?

.net - 如何列出 Win32.DLL 中的可用方法

python - 如何从 Win32_PnPEntity 实例中提取特定属性?

c++ - EvtArchiveExportedLog 失败并显示 ERROR_DIRECTORY

delphi - OpenGL:增加行数会改变抗锯齿?

c++ - glDrawElements 错误 : nvoglv32. dll OpenGL

使用递归反转堆栈的 C 程序

C、文件、路径等

c - 在 Matlab 的 c 代码中设置 #define