Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with NK_STATIC_ASSERT during compilation in MSYS2 #747

Closed
rjopek opened this issue Nov 25, 2024 · 4 comments
Closed

Issue with NK_STATIC_ASSERT during compilation in MSYS2 #747

rjopek opened this issue Nov 25, 2024 · 4 comments

Comments

@rjopek
Copy link

rjopek commented Nov 25, 2024

Hi,

I am working on creating Nuklear bindings for xBase family languages. During compilation in MSYS2, I encountered the following errors:

nuklear.h:301:61: error: size of array '_dummy_array443' is negative
  301 |   #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
nuklear.h:443:1: note: in expansion of macro 'NK_STATIC_ASSERT'
  443 | NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
nuklear.h:444:1: note: in expansion of macro 'NK_STATIC_ASSERT'
  444 | NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));  

The only way to bypass this issue and successfully compile the library and example was to comment out the following lines:

// NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
// NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));

This allowed me to proceed with testing, but I understand that this is not a proper solution.

The problem occurs only in the MSYS2 environment – everything works correctly under Linux.

What can be done to address this issue?

@riri
Copy link
Contributor

riri commented Nov 26, 2024

The solution is not to disable static asserts, but to fix what's not working on this platform :)
I'll check those later as I have an MSYS2 env at work.
Is there a specific demo/example your are compiling so that I check from the same?

@riri
Copy link
Contributor

riri commented Nov 26, 2024

As there is no existing compilation example for MSYS2, could you show how you invoke the compiler?
aka gcc/clang? which flags?

I made a quick test on demo/gdi with gcc, and out of linking errors, I don't have any compilation one.

@riri
Copy link
Contributor

riri commented Nov 26, 2024

Indeed a negative size array is illegal in C, and that's the purpose of static assertions.

That's why I ask you how you compile, which compiler is used and with which switches, to reproduce your error and find out why those sanity checks don't pass. I got the error, now I need the command line triggering this error.

@riri
Copy link
Contributor

riri commented Nov 26, 2024

The problem here lies in the assumption that sizeof(nk_size) >= sizeof(void*) is always true. In environments like MSYS2/MinGW, this assumption might not hold, leading to compilation errors.

Actually sizeof(nk_size)should be >= to sizeof(void *) whatever the platform/environment because addresses will be held in nk_size variables.

To make the library more flexible for such cases, I propose adding a conditional check for MSYS2/MinGW environments to skip static assertions when necessary.

It's not making itmore flexible, but less robust and candidate to segfaults.

The solution is more to understand why in your MSYS2 implementation, you fall on this case, because that should not occur. Once the origin of the problem is detected, we can add the various #ifdef needed to handle this.

I just need the compilation command line (and/or Makefile), as well as your environment like Windows version to see if there is some peculiar context.

@rjopek rjopek closed this as completed Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants