vendredi 25 juin 2021

Subtraction of unsigned values in return statement of a function that return signed type

I've run into code that simplified looks like this

__int64 fun(unsigned __int64 x, unsigned __int64 y)
{
    return x - y;
}

In Visual Studio it works fine even when y>x and we have proper negative value. But is it a UB or valid situation and all other compilers will handle this also properly?

Aucun commentaire:

Enregistrer un commentaire