Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

Safer NK_LEN macro

Open ryuukk opened this issue 3 years ago • 6 comments

Protects from division by 0 and when used from <= C11

https://stackoverflow.com/a/1598827

ryuukk avatar Jun 14 '22 14:06 ryuukk

C++ sizeof will never return 0.

From C++ standard, 9/3 "Classes": "Complete objects and member subobjects of class type shall have nonzero size."

aganm avatar Jun 16 '22 03:06 aganm

IMHO if the new macro helps in some real cases or for some compilers, then we can merge this. Any such examples @ryuukk ?

dumblob avatar Jun 16 '22 09:06 dumblob

C++ sizeof will never return 0.

Neither will C. The lowest addressable unit is defined to be char which will always be 1 byte. And you cannot apply sizeof to a bit-field.

N-R-K avatar Jun 29 '22 23:06 N-R-K

Sorry i didn't meant "and when used from C++"

I meant when used with a <= C11 compiler, it'll refuse to compile

ryuukk avatar Oct 28 '22 00:10 ryuukk

Looks ok to me too

Just missing nuklear.h build and version bump

riri avatar Nov 13 '23 17:11 riri