liteserver / binn

Binary Serialization
Apache License 2.0
440 stars 58 forks source link

Fix missing header for size_t #39

Closed funbiscuit closed 6 months ago

funbiscuit commented 3 years ago

Without this standard C header it doesn't compile with following error:

src\binn.h(259): error C2081: 'size_t': name in formal parameter list illegal

Library itself (binn.c) compiles normally because it includes other standard headers before binn.h so binn.h receives size_t definition. But if you include binn.h in some other C file (like in writing.c) and don't include other headers, it won't compile. stddef.h is standard header so I think it should be okay to include that. All compilers should support it.

kroggen commented 6 months ago

I never needed this include You can see the tests run fine without it Is this happening in a specific platform? Which compiler are you using? In which OS?

funbiscuit commented 6 months ago

In your tests you include a bunch of std headers before including binn.h.

Try to change order of includes in test_binn.c to this one:

#include "../src/binn.h"

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <math.h>  /* for fabs */
#include <assert.h>

You'll get an error from issue (at least I checked now and error is present on latest master). Adding extra include helps and this compiles:

#include <stddef.h>
#include "../src/binn.h"

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <math.h>  /* for fabs */
#include <assert.h>

In my program I included just binn.h in some files where I didn't need any std headers and recieved this error. I use gcc 13.2.1 on latest Arch Linux (Manjaro), but this should be the same with all compilers.

kroggen commented 6 months ago

OK, Thanks!