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

TRUE and FALSE #301

Closed
kennykerr opened this issue Mar 2, 2021 · 4 comments
Closed

TRUE and FALSE #301

kennykerr opened this issue Mar 2, 2021 · 4 comments
Labels
usability Touch-up to improve the user experience for a language projection

Comments

@kennykerr
Copy link
Contributor

Should the TRUE and FALSE constants be of type Windows.Win32.SystemServices.BOOL? Currently they're int.

@AArnott
Copy link
Member

AArnott commented Mar 3, 2021

Should BOOL be an enum with two values? 😱

@mikebattista mikebattista added the usability Touch-up to improve the user experience for a language projection label Mar 3, 2021
@weltkante
Copy link

Should BOOL be an enum with two values?

There are APIs that return more than two values (most prominently GetMessage), in case thats relevant to the decision

@weltkante
Copy link

weltkante commented Mar 5, 2021

The quote from the doc actually made me remember that often BOOL is documented as zero vs. nonzero not TRUE vs. FALSE - the constants are for generating BOOL values, not for comparing them. So making this an enum will probably lead to weird edge cases where people try to compare a BOOL with TRUE and its comparing false yet still a nonzero value.

I don't know how clean the implementation of the Windows API is in regard to nonzero BOOL values, aside from officially documented cases like GetMessage. Since all C/C++ code I've ever written or maintained never compared to TRUE literally I never ran into these cases if they exist, code always did the implicit nonzero check.

Making this an enum would be taking a leap of faith since APIs are usually not documented as returning TRUE, but rather nonzero (even if in practice that nonzero probably will be mostly TRUE anyways, but who knows for sure)

For C# projections having a struct which implicitly converts to bool by doing a nonzero check will probably be the more intuitive thing to avoid this kind of bug?

@AArnott
Copy link
Member

AArnott commented Mar 5, 2021

Agreed. Let's not define an enum. I was mostly kidding on that anyway. But I learned some important things from your comments here, so thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Touch-up to improve the user experience for a language projection
Projects
None yet
Development

No branches or pull requests

4 participants