Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-11

How to fix - Hint: Type size mismatch

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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?

   TXRectangle = record
        x, y : cshort;
        width, height : cushort;
     end;
  TRect =  record
    case Integer of
      0: (Left,Top,Right,Bottom : Longint);
      1: (TopLeft,BottomRight : TPoint);
    end;

Regards,
- Graeme -

There's no place like 127.0.0.1
Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 21 lines
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.