[fpc-pascal] Wrong assignment detected only run time without warning
Tomas Hajny
XHajT03 at hajny.biz
Fri Jun 16 15:02:11 CEST 2023
On 2023-06-16 13:46, Giuliano Colla via fpc-pascal wrote:
> Il 16/06/23 13:36, Peter B via fpc-pascal ha scritto:
>
>> Yes. Assigning a 64bit integer to a 32bit one is fine as long as the
>> range is within bounds.
>> Range of a variable can only be checked at run time.
>
> I can understand that. But the compiler generates quite a number of
> warning for potential loss of information. In that case a little
> warning wouldn't be excessive, I think.
If you compile with -CO, you should get at least a hint (if you enable
displaying them, of course):
---
{$MODE OBJFPC}
uses
SysUtils;
var
ISize: Integer;
SR: TSearchRec;
begin
FindFirst ('XYZ', faAnyFile, SR);
ISize := SR.Size;
WriteLn (ISize);
end.
===
D:\TEMP>fpc -CO -vwih t.pas
Hint: Start of reading config file ...\fpc.cfg
Hint: End of reading config file ...\fpc.cfg
Free Pascal Compiler version 3.2.2 [2021/05/15] for i386
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling t.pas
t.pas(11,8) Hint: Type size mismatch, possible loss of data / range
check error
Linking t.exe
13 lines compiled, 0.1 sec, 68800 bytes code, 4276 bytes data
3 hint(s) issued
Tomas
More information about the fpc-pascal
mailing list