Compare unsigned T with 0: what can possibly go wrong?

65 views Asked by At

Maybe a silly question, but today I've faced this type-generic code:

float f_u( unsigned T v )
{
    if ( v == 0u )
    {
        return 0.0f;
    }
    ...
    return result;
}

Is unsigned-suffix u really needed in this case?

In other words: what can possibly go wrong without using u?

UPD.

  1. The question is about C, not C++. Updated code sample.
  2. Answer to https://xyproblem.info: the actual problem is: there are another function f_s() for signed T v, which uses if ( v == u ). Now I'm thinking of merging f_u() with f_s() into common f_x(). The actual problem: in f_x() do I need to keep this u or it can be safely omitted?
0

There are 0 answers