1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 13:50:36 +00:00
QB64-PE/internal/help/_OFFSET_(function).txt

45 lines
2.1 KiB
Plaintext
Raw Normal View History

2016-03-18 11:36:04 +00:00
{{DISPLAYTITLE:_OFFSET (function)}}
2017-10-10 14:55:21 +00:00
The [[_OFFSET]] function returns the memory offset of/within a given variable.
{{PageSyntax}}
2017-10-10 14:55:21 +00:00
: {{Parameter|offset%&}} = [[_OFFSET]]({{Parameter|variable}})
2017-10-10 14:55:21 +00:00
{{PageDescription}}
* The {{Parameter|variable}} parameter can be any type of numerical or [[STRING|string]] variable name.
* API [[DECLARE LIBRARY|LIBRARY]] parameter or [[TYPE|type]] names may include '''lp, ptr''' or '''p''' which designates them as a pointer type.
* _OFFSET function return values should be stored in [[_OFFSET]] type variables. As no other variable type is 'elastic' like [[_OFFSET]], there can be no guarantee that any other variable type can hold the value of an _OFFSET.
* Returns the memory offset of variables, user-defined-types & elements, arrays & indices and the base offset of [[STRING]]s.
* Offset values are currently only useful when used in conjunction with [[_MEM]] or [[DECLARE LIBRARY]] procedures.
* OFFSET values are used as a part of the [[_MEM]] variable [[type]] in QB64; {{Parameter|variable}}.OFFSET returns or sets the current position in memory.
2017-10-10 14:55:21 +00:00
* '''Warning:''' QB64 variable length strings can move about in memory at any time. If you get the _OFFSET of a variable length sting on one line and use it on the next it may not be there anymore.''' To be safe, move variable length strings into fixed length strings first.'''
2017-10-10 14:55:21 +00:00
{{PageExamples}}
''Example:'' Using memcpy with the _OFFSET function values as parameters.
{{CodeStart}} '' ''
{{Cl|DECLARE DYNAMIC LIBRARY|DECLARE CUSTOMTYPE LIBRARY}}
{{Cl|SUB}} memcpy ({{Cl|BYVAL}} dest {{Cl|AS}} {{Cl|_OFFSET}}, {{Cl|BYVAL}} source {{Cl|AS}} {{Cl|_OFFSET}}, {{Cl|BYVAL}} bytes {{Cl|AS}} {{Cl|LONG}})
{{Cl|DECLARE LIBRARY|END DECLARE}}
2019-04-15 01:15:33 +00:00
a$ = "1234567890"
b$ = "ABCDEFGHIJ"
memcpy {{Cl|_OFFSET (function)|_OFFSET}}(a$) + 5, {{Cl|_OFFSET (function)|_OFFSET}}(b$) + 5, 5
{{Cl|PRINT}} a$ '' ''
{{CodeEnd}}
{{OutputStart}}12345FGHIJ
{{OutputEnd}}
2017-10-10 14:55:21 +00:00
{{PageSeeAlso}}
* [[_OFFSET]] {{text|(variable type)}}
* [[DECLARE LIBRARY]]
* [[DECLARE DYNAMIC LIBRARY]]
* [[Using _OFFSET]]
2019-04-15 01:15:33 +00:00
{{PageNavigation}}
<