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

using bool from stdbool.h makes FFI author life difficult #494

Closed
jangko opened this issue Dec 13, 2019 · 4 comments
Closed

using bool from stdbool.h makes FFI author life difficult #494

jangko opened this issue Dec 13, 2019 · 4 comments

Comments

@jangko
Copy link

jangko commented Dec 13, 2019

why is it difficult:

  • there is nowhere in documentation of C guarantee the size of bool. is it a byte or is it an int?
  • there is no guarantee a bool in one language will have the same size with bool from C language.
  • not all language FFI mechanism have access to C implementation specific feature.

please reconsider using a fixed-size replacement for bool.

EDIT: size_t have different size on 32 bit vs 64 bit platform. but it is well defined and well documented. In other hand a bool in stdbool.h does not have size definition.

@chfast
Copy link
Member

chfast commented Dec 13, 2019

Do you have any particular FFI project in mind?

@chfast
Copy link
Member

chfast commented Dec 13, 2019

Anyway, as far as the standard is concerned, even int type may have different size than 4. Similarly for enums.
But in practice the sizeof(_Bool) is 1: https://godbolt.org/z/marD9R

The problematic type is usually long which can be 4 or 8, depending on the compiler.

@jangko
Copy link
Author

jangko commented Dec 13, 2019

Do you have any particular FFI project in mind?

we are working to implement EVMC interface for nimbus

Anyway, as far as the standard is concerned, even int type may have different size than 4. Similarly for enums.

this is documented and well known behaviour since C89

But in practice the sizeof(_Bool) is 1: https://godbolt.org/z/marD9R

we are lucky then

I think such agreement between C compilers will pose little risk in the future.
thanks for your help. closing this issue.

@jangko jangko closed this as completed Dec 13, 2019
@axic
Copy link
Member

axic commented Dec 13, 2019

we are working to implement EVMC interface for nimbus

Please also check out #157.

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

3 participants