mirror of
https://github.com/irmen/prog8.git
synced 2024-09-09 17:55:07 +00:00
strings and arrays are no longer directly assignable to an UWORD, you need an explicit & (address-of) now
This commit is contained in:
parent
6f74fb49bd
commit
44019d1a61
@ -30,8 +30,8 @@ enum class DataType {
|
|||||||
UWORD -> targetType in setOf(UWORD, FLOAT)
|
UWORD -> targetType in setOf(UWORD, FLOAT)
|
||||||
WORD -> targetType in setOf(WORD, FLOAT)
|
WORD -> targetType in setOf(WORD, FLOAT)
|
||||||
FLOAT -> targetType == FLOAT
|
FLOAT -> targetType == FLOAT
|
||||||
STR -> targetType == STR || targetType == UWORD
|
STR -> targetType == STR
|
||||||
in ArrayDatatypes -> targetType == this || targetType == UWORD
|
in ArrayDatatypes -> targetType == this
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,18 +309,21 @@ read the syntax reference on strings.
|
|||||||
|
|
||||||
|
|
||||||
.. hint::
|
.. hint::
|
||||||
Strings and uwords (=memory address) can often be interchanged.
|
Strings/arrays and uwords (=memory address) can often be interchanged.
|
||||||
An array of strings is actually an array of uwords where every element is the memory
|
An array of strings is actually an array of uwords where every element is the memory
|
||||||
address of the string. You can pass a memory address to assembly functions
|
address of the string. You can pass a memory address to assembly functions
|
||||||
that require a string as an argument.
|
that require a string as an argument.
|
||||||
|
For regular assignments you still need to use an explicit ``&`` (address-of) to take
|
||||||
|
the address of the string or array.
|
||||||
|
|
||||||
.. caution::
|
.. caution::
|
||||||
It's probably best to avoid changing strings after they've been created. This
|
It's probably best to avoid changing the contents in strings and treat them as static.
|
||||||
includes changing certain letters by index, or by assigning a new value, or by
|
This includes changing certain letters by index, or by assigning a new value, or by
|
||||||
modifying the string via other means for example ``substr`` function and its cousins.
|
modifying the string via other means for example ``substr`` function and its cousins.
|
||||||
This is because if your program exits and is restarted (without loading it again),
|
This is because the changes persist in memory. If your program exits and is restarted
|
||||||
it will then start working with the changed strings instead of the original ones!
|
(without reloading it from disk), it will then start working with the modified strings
|
||||||
The same is true for arrays.
|
instead of the original ones!
|
||||||
|
The same is true for arrays! So be careful to (re)initialize them if needed.
|
||||||
|
|
||||||
|
|
||||||
Structs
|
Structs
|
||||||
|
@ -5,11 +5,24 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
uword foo = [1,2,3,4] ; TODO SYNTAX ERROR
|
uword foo
|
||||||
uword bar = "sdfadsaf" ; TODO SYNTAX ERROR
|
uword bar
|
||||||
|
|
||||||
|
uword[] arra = [1,2,3]
|
||||||
|
str nom = "omnom"
|
||||||
|
|
||||||
|
foo = &arra
|
||||||
|
foo++
|
||||||
|
foo = &nom
|
||||||
|
foo++
|
||||||
|
|
||||||
|
ding(nom)
|
||||||
|
ding("sdfsdfd")
|
||||||
|
|
||||||
txt.print("hello\n")
|
txt.print("hello\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub ding(uword ss) {
|
||||||
|
txt.print(ss)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user