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

FFI: Add a stdbool type for C99 _Bool/C23 bool #869

Open
williewillus opened this issue Sep 10, 2024 · 0 comments
Open

FFI: Add a stdbool type for C99 _Bool/C23 bool #869

williewillus opened this issue Sep 10, 2024 · 0 comments

Comments

@williewillus
Copy link

I misread the FFI manual, and mistakenly used the FFI boolean type to represent a C99 _Bool.

Since Chez Scheme predates C99 being common, boolean in the FFI actually just means int, which was what was commonly used before C99 _Bool. This means I was reading 3 bytes of garbage every time a C function returned a bool, causing things to evaluate to #t on the scheme side when they shouldn't.

Now that it's 2024 and C99 _Bool is pretty widely used, and C23 is even finally reserving the keyword bool for the type, so I think the FFI should add stdbool to explicitly represent this type on the Chez side. Currently, I have to assume that sizeof(bool)==1 on my platform, use unsigned-8, and do the zero-check myself. Although it's rare that someone would make their platform bools larger than 1 byte, hardcoding the size and having to do the check myself is still a minor annoyance.

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

1 participant