aliasing_20strings_20and_20byte_20arrays
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
aliasing_20strings_20and_20byte_20arrays [2018/04/17 15:00] – Added syntax highlighting tbest3112 | aliasing_20strings_20and_20byte_20arrays [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Aliasing strings and byte arrays===== | =====Aliasing strings and byte arrays===== | ||
- | //by Richard Russell, March 2014//\\ \\ //BBC BASIC for Windows// | + | //by Richard Russell, March 2014//\\ \\ BBC BASIC provides two data types in which you can store a set of byte (8-bit, or character) values: one is the **string** (for example **A$**) and the other is the **byte array** (for example **A& |
<code bb4w> | <code bb4w> | ||
- | | + | |
!(^byte$+4) = DIM(byte& | !(^byte$+4) = DIM(byte& | ||
</ | </ | ||
- | After execution of that code the string **byte$** will alias the array **byte& | + | After execution of that code the string **byte$** will alias the array **byte& |
+ | |||
+ | Note that array indexes are **zero-based** | ||
<code bb4w> | <code bb4w> | ||
- | | + | |
- | ?(^byte$+4) = DIM(byte& | + | |
- | ?(^byte$+5) = (DIM(byte& | + | |
- | </ | + | |
- | Note that array indexes are **zero-based** and string indexes are **one-based** so for example **byte& | + | |
- | <code bb4w> | + | |
- | !^byte$ | + | |
!(^byte$+4) = DIM(byte& | !(^byte$+4) = DIM(byte& | ||
</ | </ | ||
Now the array and string indexes will align.\\ \\ Do not attempt to change the **length** of the string; if you do that you will confuse BBC BASIC, and may well crash it. In particular do not empty the string (e.g. **byte$ = "" | Now the array and string indexes will align.\\ \\ Do not attempt to change the **length** of the string; if you do that you will confuse BBC BASIC, and may well crash it. In particular do not empty the string (e.g. **byte$ = "" |
aliasing_20strings_20and_20byte_20arrays.1523977237.txt.gz · Last modified: 2024/01/05 00:18 (external edit)