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

Patched raygui to make it both C and C++ compliant #44

Merged
merged 1 commit into from
Jul 15, 2019

Conversation

SasLuca
Copy link
Contributor

@SasLuca SasLuca commented Jul 14, 2019

Explanation

I encountered a lot of errors and warning when using raygui in my C++ project.
I modified raygui.h to make it both C and C++ compliant.

The most significant changes that I made are:

  1. For curly intialisations I created a macro named CURLY_INIT which expands to StructName { } in C++ and (StructName) { } in C.

  2. I had to add a lot of casts to float because in C++ I would get the error "Conversion from 'int' to 'float' requires a narrowing conversion".

I tested by compiling an example in C and one in C++ using the MSVC compiler, but I didn't add my testing setup to the project since I didn't want to mess with it that much.
In my testing setup I also didn't set the warning level manually, I just left it on the default, so there might be more warnings when compiling for C++ on higher warning levels.
I also didn't check for compliance with other compilers, though the changes are made are straightforward enough that I don't think it will be a problem.

Conclusion

Of course the cost of this change is that from now on when using curly brace initialisation we should use the macro CURLY_INIT which is not as nice and considering this is a C project this does add a bit of ugliness/friction to the code for the sake of compatibility. I guess we could give a nicer name to the macro.
Also people would need to be careful since certain implicit conversions are not allowed in C++ and require casts.
It would also mean that the code would need to be tested with both a C and C++ compiler in order to maintain compatibility.
Personally I use this library in a C++ codebase so I am willing to update it to ensure C++ compatibility when people make breaking changes.

…egarding curly initialisation and int to float conversions.
@AregevDev
Copy link

Nice work, I also got many warning while compiling raygui.

Very awesome 👍

@raysan5 raysan5 merged commit f099d90 into raysan5:master Jul 15, 2019
@raysan5
Copy link
Owner

raysan5 commented Jul 15, 2019

Thanks for the improvement! :)

Just a note: This improvement is only required for C++ under MSVC

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

Successfully merging this pull request may close these issues.

3 participants