ThingSet / thingset-device-library

ThingSet library for resource-constrained devices written in C/C++
https://thingset.io/thingset-device-library/
Apache License 2.0
13 stars 6 forks source link

Issue with cstdbool header #27

Closed cfoucher-laas closed 2 years ago

cfoucher-laas commented 2 years ago

Hello Martin,

We at OwnTech are trying to use recent versions of the library, and face an issue with the following include in thingset.h:

#include <cstdbool>

This produces the following error message:

zephyr/third_party_modules/thingset/src/thingset.h:19:10: fatal error: cstdbool: No such file or directory
 #include <cstdbool>

Our project is compiled as C++, so the #ifdef __cplusplus section in which the include is located is active.

As I understand it, this file used to be a compatibility file for C compilers, and is thus is not required when using a C++ compiler. Moreover, this file seems to be deprecated in recent versions of the C++ standard.

I can confirm that removing this single line in the source fixes the error. Editing the line to include <stdbool.h> instead also allows for successful compilation.

Do you think you could edit or remove this include without side effects on the library?

Regard,

 The OwnTech team
martinjaeger commented 2 years ago

Thanks for reporting the issue.

I'm not too familiar with the specifics of C compatibility headers, to be honest.

@b0661 You introduced the differentiation between C and C++ standard headers in thingset.h and I'm sure you had a good reason. Do you have an idea how to fix above issue? Previously I just didn't care and always included <stdbool.h> for C and C++. Can this cause any problems?

b0661 commented 2 years ago

Do you have an idea how to fix above issue? Previously I just didn't care and always included for C and C++.

@martinjaeger, I think, going for in C++ and C code is the right way. This puts the burden on the C++ compiler to provide a compatible header and should work up to C++20, as @cfoucher-laas mentioned.

Can this cause any problems?

I don't know. My testing does not enable C++20. Using stdbool.h as such works in my test setup.

martinjaeger commented 2 years ago

Alright, thanks @b0661. I will create a PR later.