nuklear icon indicating copy to clipboard operation
nuklear copied to clipboard

Does not compile with C++

Open adihodos opened this issue 10 years ago • 1 comments

The code will not compile with a C++ compiler because of the nested structs. Basically they don't work the same for C and C++. I was able to get around it by doing some ugly ifdefs

NK_API int
nk_style_push_font(struct nk_context *ctx, struct nk_user_font *font)
{
#if !defined(__cplusplus)
    struct nk_style *style;
    struct nk_config_stack_user_font *font_stack;
    struct nk_config_stack_user_font_element *element;
#endif

    NK_ASSERT(ctx);
    if (!ctx) return 0;

#if defined(__cplusplus)
    auto
#endif
    style = &ctx->style;

#if defined(__cplusplus)
    auto
#endif    
    font_stack = &ctx->stacks.fonts;
    NK_ASSERT(font_stack->head < (int)NK_LEN(font_stack->elements));
    if (font_stack->head >= (int)NK_LEN(font_stack->elements))
        return 0;

#if defined(__cplusplus)
    auto
#endif    
    element = &font_stack->elements[font_stack->head++];
    element->address = &ctx->style.font;
    element->old_value = ctx->style.font;
    ctx->style.font = font;
    return 1;
}

This will only work if you're compiling with -std=c++11 or greater, since it relies on type inference.

adihodos avatar Aug 31 '16 17:08 adihodos

Thanks for the issue I fixed the problem in commit: 4cc1778f9ce2d4562eedc75115d7db97876495a7. Did not realize C++ does not like named structs inside structs.

vurtun avatar Aug 31 '16 17:08 vurtun