stupid change to avoid compiler warning#142
Merged
kernelwernel merged 1 commit intokernelwernel:mainfrom Sep 7, 2024
NotRequiem:main
Merged
stupid change to avoid compiler warning#142kernelwernel merged 1 commit intokernelwernel:mainfrom NotRequiem:main
kernelwernel merged 1 commit intokernelwernel:mainfrom
NotRequiem:main
Conversation
**Warning**
```
Warning C4244 'initializing': conversion from '_Ty' to '_Ty2', possible loss of data
with
[
_Ty=int
]
and
[
_Ty2=VM::u8
] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\utility 247
```
**Explanation**
The warning suggests that converting between these types (i.e., from DWORD to u8) may cause data loss since DWORD is 32-bit and u8 is only 8-bit.
**Solution**
All the values you're assigning to the u8 type are valid and will fit within uint8_t. Therefore, casting them as static_cast<u8> will work fine to supress the MSVC compiler warning without any data loss:
- The first value, 6, is well within the range of uint8_t (0-255).
- The rest of the values (7, 8, 10, 11) also fit within the valid range of uint8_t.
By explictly casting the values to "u8" (which is an alias for uint8_t) during initialization, we make it clear that we're aware of the conversion to the compiler.
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.
Warning
Explanation
The warning suggests that converting between these types (i.e., from DWORD to u8) may cause data loss since DWORD is 32-bit and u8 is only 8-bit.
Solution
All the values you're assigning to the u8 type are valid and will fit within uint8_t. Therefore, casting them as static_cast will work fine to supress the MSVC compiler warning without any data loss:
By explictly casting the values to "u8" (which is an alias for uint8_t) during initialization, we make it clear that we're aware of the conversion to the compiler.