QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Petr on April 28, 2019, 06:44:35 am

Title: Why can not use _OFFSET type in FOR... NEXT loop?
Post by: Petr 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?
Title: Re: Why can not use _OFFSET type in FOR... NEXT loop?
Post by: Raven_Singularity 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?
Title: Re: Why can not use _OFFSET type in FOR... NEXT loop?
Post by: SMcNeill 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.  ;)
Title: Re: Why can not use _OFFSET type in FOR... NEXT loop?
Post by: Petr 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?
Title: Re: Why can not use _OFFSET type in FOR... NEXT loop?
Post by: Raven_Singularity on April 29, 2019, 02:45:30 pm
+1 on automatic conversion of offsets to other integer types in a future QB64 release!
Title: Re: Why can not use _OFFSET type in FOR... NEXT loop?
Post by: luke 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 :)