Skip to content

stupid change to avoid compiler warning#142

Merged
kernelwernel merged 1 commit intokernelwernel:mainfrom
NotRequiem:main
Sep 7, 2024
Merged

stupid change to avoid compiler warning#142
kernelwernel merged 1 commit intokernelwernel:mainfrom
NotRequiem:main

Conversation

@NotRequiem
Copy link
Copy Markdown
Collaborator

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 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.

**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.
@kernelwernel kernelwernel merged commit 1a98569 into kernelwernel:main Sep 7, 2024
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.

2 participants