Range check, converting extended to double lazarus / 21-General ---------------------------------------------------------------------- Markus · 2025-05-16 09:59 I just found an error in my code where the program wrote to an item 0 of an array that was defined from 1 upwards. This produced a strange behavior where another variable was changed unintentionally. I assumed that an error message should have appeared, but it did not happen. Someone wrote that such problems can be avoided by activating: Project / Project Options / Compiler Option / Debugging / Checks / Range. After activating this option (-Cr) to avoid such programming errors in the future, I get other problems, for instance when passing a extended variable to a function that uses TDateTime (=double) as parameter, which was accepted before. 1) Is there a way to only get error messages when an array index is out of range? 2) Is there a way to convert extended -> double (reduce precision to double) ---------------------------------------------------------------------- jamie · 2025-05-16 10:06 Use range check, its in the compiler options of your project options As for extended. Dont use it? Btw, welcome to real hard core coding ---------------------------------------------------------------------- Markus · 2025-05-16 10:51 Don't use it? Nice idea.. The problem is that it is part of a function unit which I use in about 10 other projects. Changing that function could have unwanted effects on the other projects. ---------------------------------------------------------------------- Zvoni · 2025-05-16 10:58 Quote from: Markus on May 16, 2025, 12:51:17 pmDon't use it? Nice idea.. The problem is that it is part of a function unit which I use in about 10 other projects. Changing that function could have unwanted effects on the other projects. Use overloads? ---------------------------------------------------------------------- Paolo · 2025-05-16 11:28 What OS ? On win64 extended = double. In general the jamie advice is right, do not use extended that could be not available everywhere. ---------------------------------------------------------------------- Markus · 2025-05-16 12:29 I am using Windows 10, 64-bit. I get a runtime error with this compiler option (-Cr) switched on when calling a special seldom used function with an extended variable which is actually defined to get TDateTime as input parameter. The variable value is nearly zero in that case (something with a large negative exponent). I will check if extended could be replaced by double. The original idea was that some often used procedures which I have in a unit used in all projects have the parameter extended to be able to be called by all kinds of real values. Maybe this was a wrong idea.. ---------------------------------------------------------------------- tetrastes · 2025-05-16 12:42 Quote from: Markus on May 16, 2025, 11:59:44 amAfter activating this option (-Cr) to avoid such programming errors in the future, I get other problems, for instance when passing a extended variable to a function that uses TDateTime (=double) as parameter, which was accepted before. Just because it was accepted doesn't mean it worked properly. You have to find the cause of these problems, as f.e. DateTimeToStr(extended_var) works without problem (at i386-win32 with "true" 80-bit extended). Quote from: Markus on May 16, 2025, 11:59:44 am2) Is there a way to convert extended -> double (reduce precision to double) double_var := extended_var double(extended_var) works also, except in $MODE DELPHI (fpc 3.2.2) Quote from: Markus on May 16, 2025, 02:29:33 pmI am using Windows 10, 64-bit. But what is bitness of your programs?