Remove warnings message during snesbrr compilation#185
Merged
RetroAntho merged 1 commit intoalekmaul:developfrom Apr 9, 2023
Merged
Remove warnings message during snesbrr compilation#185RetroAntho merged 1 commit intoalekmaul:developfrom
RetroAntho merged 1 commit intoalekmaul:developfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi all,
Here a very small change to avoid warnings messages during the
snesbrrcompilation:The errors are warnings generated by the compiler indicating that the left operand of a shift expression in the "basemath.h" header file is negative. Specifically, the warnings are related to the left shift operation (-1 << N - 1) used in the implementation of the "clamp" function.
The "clamp" function is a template function that takes a single parameter of type T and returns a value that is limited to a range of [0, 2^N - 1], where N is an unsigned integer template parameter.
In the warning message, the compiler is pointing out that the expression (-1 << (N - 1)) is resulting in a negative value, which can lead to undefined behavior in C++. This is because the left shift operator shifts the bits of the operand to the left and fills the vacated bits with zeroes. However, when the left operand is negative, the result of the left shift is implementation-defined in C++.
To fix this warning, we modify the implementation of the "clamp" function in the "basemath.h" header file to use an unsigned integer instead of a signed integer for the "low" variable. we also use the "static_cast" operator to convert the result of the left shift operation to an unsigned integer.