C5919: Conversion of floating to unsigned integral

[WARNING]

Description

In ANSI-C the result of a conversion operation of a (signed) floating type to a unsigned integral type is undefined. One implementation may return 0, another the maximum value of the unsigned integral type or even something else. Because such behavior may cause porting problems to other compilers, a warning message is issued for this.

Example
    float f = -2.0;

  
    unsigned long uL = f; // message C5919 here

  
Tips

To avoid the undefined behavior, first assign/cast the floating type to a signed integral type and then to a unsigned integral type.

See also