Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

error: size of array '_dummy_array435' is negative

Open GuckTubeYT opened this issue 4 years ago • 6 comments

So, i want to build this example

#include #include "nuklear.h" using namespace std;

int main() { struct nk_context ctx; nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);

enum {EASY, HARD};
static int op = EASY;
static float value = 0.6f;
static int i =  20;

if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
    NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
    /* fixed widget pixel width */
    nk_layout_row_static(&ctx, 30, 80, 1);
    if (nk_button_label(&ctx, "button")) {
        /* event handling */
    }

    /* fixed widget window ratio width */
    nk_layout_row_dynamic(&ctx, 30, 2);
    if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
    if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;

    /* custom widget pixel width */
    nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
    {
        nk_layout_row_push(&ctx, 50);
        nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
        nk_layout_row_push(&ctx, 110);
        nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
    }
    nk_layout_row_end(&ctx);
}
nk_end(&ctx);

} and then, i got that error

error: size of array '_dummy_array435' is negative error: size of array '_dummy_array436' is negative

How to fix that? i use CodeBlocks Sorry for bad grammar

GuckTubeYT avatar Jul 30 '21 12:07 GuckTubeYT

It looks like the NK_STATIC_ASSERT macro going off, which in turn means there's something badly wrong with the compiler/environment. Could you provide more details on compiler version and the OS you're compiling on? Also please provide the full error message so that it is evident which static assert fails.

lockie avatar Aug 14 '21 10:08 lockie

It looks like the NK_STATIC_ASSERT macro going off, which in turn means there's something badly wrong with the compiler/environment. Could you provide more details on compiler version and the OS you're compiling on? Also please provide the full error message so that it is evident which static assert fails.

i use windows 10, gcc version = 8.1.0, Target = x86_64-w64-mingw32

GuckTubeYT avatar Aug 17 '21 04:08 GuckTubeYT

I was able to reproduce with Wine and Mingw using GCC 8.1.0. Looks like Nuklear incorrectly typedefs integer types under this environment. This needs to be fixed, meanwhile @GuckTubeYT you can #define NK_INCLUDE_FIXED_TYPES before including Nuklear header, this should do the trick.

lockie avatar Aug 17 '21 06:08 lockie

For the reference, here are failing static asserts:

nuklear.h:435:1: note: in expansion of macro 'NK_STATIC_ASSERT'
 NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));

nuklear.h:436:1: note: in expansion of macro 'NK_STATIC_ASSERT'
 NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));

nuklear.h:5772:1: note: in expansion of macro 'NK_STATIC_ASSERT'
 NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));

nuklear.h:5773:1: note: in expansion of macro 'NK_STATIC_ASSERT'
 NK_STATIC_ASSERT(sizeof(nk_ptr) == sizeof(void*));

nk_size gets to be defined as unsigned long under aforementioned environment. Also, judging by the following errors, nk_ptr also gets incorrectly defined just as long unsigned int.

lockie avatar Aug 17 '21 06:08 lockie

Hi,

lockie and GuckTubeYT

My compilation method is as follows, from the headers the static library is made first.

x86_64-w64-mingw32 for my environment it has the same errors #define NK_INCLUDE_FIXED_TYPES adding didn't change anything.

../../../../../../include/nuklear_allegro5/../nuklear.h:293:61: error: size of array '_dummy_array435' is negative
  293 |   #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
      |                                                             ^~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:282:46: note: in definition of macro 'NK_STRING_JOIN_IMMEDIATE'
  282 | #define NK_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2
      |                                              ^~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:284:36: note: in expansion of macro 'NK_STRING_JOIN_DELAY'
  284 | #define NK_STRING_JOIN(arg1, arg2) NK_STRING_JOIN_DELAY(arg1, arg2)
      |                                    ^~~~~~~~~~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:289:32: note: in expansion of macro 'NK_STRING_JOIN'
  289 |   #define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__LINE__)
      |                                ^~~~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:293:46: note: in expansion of macro 'NK_UNIQUE_NAME'
  293 |   #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
      |                                              ^~~~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:435:1: note: in expansion of macro 'NK_STATIC_ASSERT'
  435 | NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
      | ^~~~~~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:293:61: error: size of array '_dummy_array436' is negative
  293 |   #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
      |                                                             ^~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:282:46: note: in definition of macro 'NK_STRING_JOIN_IMMEDIATE'
  282 | #define NK_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2
      |                                              ^~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:284:36: note: in expansion of macro 'NK_STRING_JOIN_DELAY'
  284 | #define NK_STRING_JOIN(arg1, arg2) NK_STRING_JOIN_DELAY(arg1, arg2)
      |                                    ^~~~~~~~~~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:289:32: note: in expansion of macro 'NK_STRING_JOIN'
  289 |   #define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__LINE__)
      |                                ^~~~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:293:46: note: in expansion of macro 'NK_UNIQUE_NAME'
  293 |   #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
      |                                              ^~~~~~~~~~~~~~
../../../../../../include/nuklear_allegro5/../nuklear.h:436:1: note: in expansion of macro 'NK_STATIC_ASSERT'
  436 | NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));

rjopek avatar Nov 04 '22 09:11 rjopek

@lockie, @GuckTubeYT

I forgot to add that since Linux the same compilation method works flawlessly, everything is fine.

rjopek avatar Nov 04 '22 09:11 rjopek

I encountered same issue, but I thought maybe I was using it wrong? Has it been resolved?

l-t-m-f avatar Mar 27 '23 00:03 l-t-m-f

I can't reproduce it with NK_INCLUDE_FIXED_TYPES macro defined, so looks like the workaround still works. Just to be sure, do you #define NK_INCLUDE_FIXED_TYPES before including any Nuklear headers?

lockie avatar Mar 27 '23 04:03 lockie

thanks its work

GuckTubeYT avatar Apr 08 '23 12:04 GuckTubeYT

What is the solution if we want to enforce C89 compliance? since stdint.h (used by NK_INCLUDE_FIXED_TYPES) requires C99?

otonoton avatar Apr 05 '24 21:04 otonoton

hi, i am also getting same error "error: size of array '_dummy_array435' is negative ".i have already included headers and defines in a project "/* nuklear - 1.32.0 - public domain */ #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <stdarg.h> #include <string.h> #include <math.h> #include <assert.h> #include <limits.h> #include <time.h>

#include <SDL2/SDL.h>

#define NK_INCLUDE_FIXED_TYPES #define NK_INCLUDE_STANDARD_IO #define NK_INCLUDE_STANDARD_VARARGS #define NK_INCLUDE_DEFAULT_ALLOCATOR #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT #define NK_INCLUDE_FONT_BAKING #define NK_INCLUDE_DEFAULT_FONT #define NK_IMPLEMENTATION #define NK_SDL_RENDERER_IMPLEMENTATION #include "nuklear.h" #include "nuklear_sdl_renderer.h"

i am using codeblocks and i have already included search paths? please help

Regards Shrikant Vaishnav

shrikantvaishnav avatar Jun 28 '24 14:06 shrikantvaishnav