Re: [fpc-pascal] Range checks

2018-01-30 Thread Adriaan van Os
Jonas Maebe wrote: Actually, it won't help because "qword - 1" will still be evaluated as qword. The issue is that there is no safe way to evaluate this with range checking that is correct in all cases without a 128 bit integer type: 1) if you evaluate it as qword, you get a range error if

Re: [fpc-pascal] Range checks

2018-01-29 Thread Santiago A.
El 27/01/18 a las 15:10, C Western escribió: The following innocuous looking code generates a range check error: {$R+} function Count: qword; begin   Result := 0; end; var   i: Integer; begin   for i := 0 to Count-1 do     WriteLn(i); end. I can (more or less) see why, but it means that I

Re: [fpc-pascal] Range checks

2018-01-27 Thread Dmitry Boyarintsev
On Sat, Jan 27, 2018 at 12:51 PM, Dmitry Boyarintsev < skalogryz.li...@gmail.com> wrote: > > imho, bad approach to adjust compiler for not safe code. > However, getting a compiler warning would be nice. > > Some time ago, the compiler has been extended with for-in syntax: > > var > SubView :

Re: [fpc-pascal] Range checks

2018-01-27 Thread Dmitry Boyarintsev
On Sat, Jan 27, 2018 at 12:30 PM, C Western wrote: > > The actual code that triggered my interest was: > > procedure LCLViewExtension.lclSetEnabled(AEnabled: Boolean); > var > ns : NSArray; > i : integer; > obj : NSObject; > begin > ns := subviews; > for i := 0 to

Re: [fpc-pascal] Range checks

2018-01-27 Thread C Western
On 27/01/18 16:28, Jonas Maebe wrote: Jonas Maebe wrote: C Western wrote: The following innocuous looking code generates a range check error: {$R+} function Count: qword; begin Result := 0; end; var i: Integer; begin for i := 0 to Count-1 do WriteLn(i); end. I can (more or

Re: [fpc-pascal] Range checks

2018-01-27 Thread Jonas Maebe
Jonas Maebe wrote: > C Western wrote: >> The following innocuous looking code generates a range check error: >> >> {$R+} >> function Count: qword; >> begin >> Result := 0; >> end; >> var >> i: Integer; >> begin >> for i := 0 to Count-1 do >> WriteLn(i); >> end. >> >> I can (more or

Re: [fpc-pascal] Range checks

2018-01-27 Thread Jonas Maebe
C Western wrote: > The following innocuous looking code generates a range check error: > > {$R+} > function Count: qword; > begin > Result := 0; > end; > var > i: Integer; > begin > for i := 0 to Count-1 do > WriteLn(i); > end. > > I can (more or less) see why I changed the type used

Re: [fpc-pascal] Range checks

2018-01-27 Thread Dmitry Boyarintsev
On Sat, Jan 27, 2018 at 9:10 AM, C Western wrote: > > I can (more or less) see why, but it means that I can't (for example) > compile the Cocoa widget set in 64 bit with bounds checking on, as then > qword seems to be used as a count for, for example, NSarray. > > how about

Re: [fpc-pascal] Range checks

2018-01-27 Thread C Western
On 27/01/18 15:06, Adriaan van Os wrote: C Western wrote: The following innocuous looking code generates a range check error: The code shouldn't generate a range check error, as the target type is signed. Note that shifting the loop variable to Int64 still triggers the range check

Re: [fpc-pascal] Range checks

2018-01-27 Thread Sven Barth via fpc-pascal
On 27.01.2018 15:10, C Western wrote: > The following innocuous looking code generates a range check error: > > {$R+} > function Count: qword; > begin >   Result := 0; > end; > var >   i: Integer; > begin >   for i := 0 to Count-1 do >     WriteLn(i); > end. > > I can (more or less) see why, but

Re: [fpc-pascal] Range checks

2018-01-27 Thread Dmitry Boyarintsev
On Sat, Jan 27, 2018 at 10:06 AM, Adriaan van Os wrote: > > > The code shouldn't generate a range check error, as the target type is > signed. > Count returns Unsigned Qword. unsigned $ is beyond 32-bit boundary. The similar issue, but more explicit. {$R+}

Re: [fpc-pascal] Range checks

2018-01-27 Thread Adriaan van Os
C Western wrote: The following innocuous looking code generates a range check error: The code shouldn't generate a range check error, as the target type is signed. Note that Oberon was designed by Niklaus Wirth specifically to prevent this kind of problems. See the notes on type inclusion in

[fpc-pascal] Range checks

2018-01-27 Thread C Western
The following innocuous looking code generates a range check error: {$R+} function Count: qword; begin Result := 0; end; var i: Integer; begin for i := 0 to Count-1 do WriteLn(i); end. I can (more or less) see why, but it means that I can't (for example) compile the Cocoa widget set