Quad support with For/Next

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Quad support with For/Next

Post by Keya »

Can't do, but would be nice:

Code: Select all

For i.q = 1 To 5    ;for example if i is a file offset and we want to read more than 4GB
 Debug Str(i)
Next
Can do:

Code: Select all

i.q=0
Repeat
 i+1
 Debug Str(i)
Until i = 5

i.q=0
While i < 5
 i+1
 Debug Str(i)
Wend
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Quad support with For/Next

Post by normeus »

I get no error output with the following code on win 7 5.42LTS 64x. ( I wish I would get an error)

I guess it is because it is a runtime error but since the numeric limit is built into the statement I would like a cryptic <Buffer overflow error> from the debugger.
I know the "TO" becomes -122..etc.. and that's why the loop does not run
but the compiler knows I am using a FOR NEXT and it should warn me about using larger variable types.

Code: Select all

 Define i.q
  Define upper.q=  9230000000000000000 ; change the 3 to a 2 and it will run. 
                   ;9223372036854775807 max 64bit int
  Define lower.q = 8900000000000000001 
  
  ;step
  #stec=            2150000000 ; change the 5 to 4 from #stec to get right output
                   ;2147483648 max 32bit int
  
  For i = lower To upper Step #stec   
      Debug i
  Next
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Quad support with For/Next

Post by Keya »

sorry I should've clarified i meant support for x86! :) It's not a problem in x64 because Integer vars which For/Next uses are already 64bit, but Integer vars on x86 are 32bit and they don't let you use Quad
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Quad support with For/Next

Post by wilbert »

I didn't know this isn't possible.
It might be nice if it would be supported but when it comes to performance, it's better to do things differently.
I don't know if the difference is big but a quad based loop on x86 would be slower since the value to work with doesn't fit in a register.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply