Author Topic: Why can not use _OFFSET type in FOR... NEXT loop?  (Read 3445 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Why can not use _OFFSET type in FOR... NEXT loop?
« on: April 28, 2019, 06:44:35 am »
Why is this bad?

Code: QB64: [Select]
  1.  
  2. for ss = m.offset to m.offset +  m.size
  3.  
  4.  
  5. LOOP UNTIL pass
  6.  
  7.  

is this caused, because internaly is FOR...NEXT pointer defined as smaller data type?

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: Why can not use _OFFSET type in FOR... NEXT loop?
« Reply #1 on: April 28, 2019, 09:04:47 am »
I just ran into this issue stepping over image data in RAM.  I'm not sure why _OFFSET variables can't be used as regular integers in FOR loops, but they can't.  Seems convoluted, but oh well.

In your case, set your ss variable to an integer type, such as LONG.  _OFFSET, it seems, is only used to return an offset and doesn't support actually changing the offset value.  Sort of a read only variable type?

Marked as best answer by Petr on April 28, 2019, 12:44:04 pm

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Why can not use _OFFSET type in FOR... NEXT loop?
« Reply #2 on: April 28, 2019, 12:43:56 pm »
ConvertOffset — http://qb64.freeforums.net/thread/52/convert-offset-integer64

That’s all you need, and you’re good to go — both for 64-bit and 32-bit versions.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Why can not use _OFFSET type in FOR... NEXT loop?
« Reply #3 on: April 28, 2019, 04:43:45 pm »
Thank you both for your answers. Steve, so I have to say about this be exactly the kind of blindness that one knows, but it doesn't connect.  Your sample program returned me back to reality. Of course! 32bit and 64bit systems! Thank you very much for your function. Maybe you, as a developer, if you wanted to implant it in a new release of QB64, could us get rid of this pain?

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: Why can not use _OFFSET type in FOR... NEXT loop?
« Reply #4 on: April 29, 2019, 02:45:30 pm »
+1 on automatic conversion of offsets to other integer types in a future QB64 release!

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Why can not use _OFFSET type in FOR... NEXT loop?
« Reply #5 on: May 03, 2019, 07:25:28 am »
Funnily enough many of the limitations on what you can do with an _OFFSET are the intentionally.

When they were first added it was thought they would be strictly for DECLARE LIBRARY and all the casting restrictions are meant to give you a fuzzy feeling of "safety". Of course, this just means we have to find hacks around the safety in even more unsafe ways :)