[fpc-pascal] How to fix - Hint: Type size mismatch

Michael Van Canneyt michael.vancanneyt at wisa.be
Sat Nov 4 10:15:27 CET 2006



On Sat, 4 Nov 2006, Graeme Geldenhuys wrote:

> Hi,
> 
> I am trying to clean up the fpGFX code and trying to get rid of all
> compiler warnings.
> I get the following compiler hint on every line in the RectToXRect
> function. Using FPC 2.1.1 under Linux.
> 
> Hint: Type size mismatch, possible loss of data / range check error
> 
> function RectToXRect(const ARect: TRect): TXRectangle;
> begin
>  Result.x      := ARect.Left;
>  Result.y      := ARect.Top;
>  Result.width  := ARect.Right - ARect.Left;
>  Result.height := ARect.Bottom - ARect.Top;
> end;
> 
> 
> I understand the hint, and agree with it, but what do I need to do, to
> fix/remove it?  The TRect and TXRectangle are defined as shown below.
> Could I cast ARect's fields to remove the hint?

No.
The result of a substraction is always a signed type. Assigning this
to an unsigned type will trigger the hint. Maybe abs() will do the
trick, but I am not sure.

What you could try to do is
  cshort(result.width):=ARect.Right - ARect.Left;

Michael.



More information about the fpc-pascal mailing list