[fpc-pascal] Assign int64 to int32 shows no warnings at compilation time

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Tue Dec 18 18:27:02 CET 2018


On 18/12/2018 17:13, Graeme Geldenhuys wrote:
> Is there a FPC command line parameter to enable warnings or errors for
> the following situation at compile time? All logic tells me that
> detecting this an runtime only is WAY to late in the game!


Just as a comparison, here is the same code, but in Java.


===========================================
public class Overflow {

    public static void main(String[] args) {

        int d32;
        long d64;

        d32 = Long.MAX_VALUE;

        System.out.println(d32);
        System.out.println(d64);

    }

}
==========================================


$ javac Overflow.java
Overflow.java:8: error: incompatible types: possible lossy conversion
from long to int
        d32 = Long.MAX_VALUE;
                  ^
1 error




The error is raised at compile time, which seems a LOT more logical to
me. After all, we don't want our programs to crash on site at a client -
then we look bad. :-/ I'd rather fix the code long before the client
sees it. ;-)


Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp



More information about the fpc-pascal mailing list