C ++ Need for typecasting int for unsigned int

I had this code as part of a C ++ project

unsigned int fn() {
    //do some computations
    int value = ....

    if(value <= 0)
        return 0;
    return (unsigned int)value;
}

I do not need to use the cast in the last return expression, since all negative numbers will be caught in the if statement (from where 0 is returned).

And besides, this function fnis called from another function (whose return type int), which simply returns the value returned fn.

Thanks..

+4
source share
2 answers

The goal is to disable a compiler warning that might otherwise be issued.

+4
source

, , , , .

-1

Source: https://habr.com/ru/post/1615788/


All Articles