What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

WhatMeWorry kheaser at gmail.com
Fri May 16 19:04:24 UTC 2025


/+ SDL3 has a function
bool SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha);
which has a Uint8 for one of its parameters.  So I try to use a 
ubyte
+/


void main()
{
     ubyte a;
     a = a + 5; // onlineapp.d(11): Error: cannot implicitly 
convert expression `cast(int)a +
                   5` of type `int` to `ubyte`

     import core.stdc.stdint;
     uint8_t b;
     b = b + 5; // onlineapp.d(17): Error: cannot implicitly 
convert expression `cast(int)b +
                   5` of type `int` to `ubyte`

     cast(uint8_t) b = cast(uint8_t) b + cast(uint8_t) 5;  // 
onlineapp.d(19): Error: cannot
                                                              
implicitly convert expression
                                                              
`cast(int)b + 5` of type `int`
                                                              to 
`ubyte`

}


More information about the Digitalmars-d-learn mailing list