Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've had a bit of a trip tracking down a completely bamboozling bug, where certain member offsets in my structs were inconsistent throughout my program when compiling on Windows. It turns out this was caused by the fact that
raylib.h
defines its ownbool
data type if it deduces thatstdbool.h
cannot be used, and the size of this type is not necessarily the same as the size ofbool
asstdbool.h
defines it. Consequently, depending on whether the compiler had seenstdbool.h
orraylib.h
when it came across the definition of my structs, it would generate different member layouts in different compilation units for those structs which hadbool
members. If I passed one struct from one compilation unit to another, member values would appear to be completely different.The reason why raylib deemed
stdbool.h
unavailable was because MSVC does not define__STDC__
unless the /Za compiler option is provided. Even after setting an explicit C standard in my CMake project, and disabling compiler extensions, CMake still did not add this compiler option. Rather than rely on that option, and only fix this problem for myself, I thought I'd make a PR to improve the way the boolean type is defined in raylib.This PR makes the following changes:
stdbool.h
(at least, every check that I could find) has been updated to explicitly check the MSVC version if the__STDC__
check fails. Since Microsoft added C99 support in VS2013, the check has been augmented to check whether_MSC_VER
is at least1800
.false
andtrue
types have been updated tofalse = 0
andtrue = !false
. This ensures thatfalse
is always and obviously0
, and that true is defined as whatever the compiler considers not to be false, as opposed to a numerical1
.raudio.c
forcibly undefined thebool
type on Windows, and this caused this file to fail compilation with the new changes. I'm not sure why that was the case, but removing this code fragment did not break compilation for me with the new changes added.