Forum
String Adress wrong (*solved*) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: String Adress wrong (*solved*) (/showthread.php?tid=253)



String Adress wrong (*solved*) - LCD - 06-18-2010

Strangely my proportional Print SUB from Tips section, with example, does not work anymore with the latest development version of ZXBC, because the address of text in b$ is returned incorrectly (in ROM).
Code:
DIM b$ AS STRING
b$="test"
PRINT PEEK(Uinteger,@b$)+2
It does not return the correct address and compiled program says "A Invalid argument" at the end.
Code:
DIM b$ AS STRING
dim adr as uinteger
b$="test"
adr=PEEK(Uinteger,@b$)+2
print adr
Does not change anything.
Code:
adr=@b$
comes with a "Undefined label '_test_b'." if used in SUBs


Re: String Adress wrong - boriel - 06-18-2010

LCD Wrote:Strangely my proportional Print SUB from Tips section, with example, does not work anymore with the latest development version of ZXBC, because the address of text in b$ is returned incorrectly (in ROM).
Code:
DIM b$ AS STRING
b$="test"
PRINT PEEK(Uinteger,@b$)+2
It does not return the correct address and compiled program says "A Invalid argument" at the end.
Code:
DIM b$ AS STRING
dim adr as uinteger
b$="test"
adr=PEEK(Uinteger,@b$)+2
print adr
Does not change anything.
Code:
adr=@b$
comes with a "Undefined label '_test_b'." if used in SUBs

As expected this is due to the (@x + N) optimization. In fact, @b + 2 might be not constant since it's a mutable object (a string). This is something I have to study...


Re: String Adress wrong - LCD - 06-18-2010

boriel Wrote:As expected this is due to the (@x + N) optimization. In fact, @b + 2 might be not constant since it's a mutable object (a string). This is something I have to study...
So maybe if it is a mutable object, you can add a function like AddressOf(b$) or similar? It would be less tragic if only POKE STRING adress,String$ and PEEK (STRING,adress[,length]) would work.


Re: String Adress wrong - boriel - 06-19-2010

I have a question about your 1st example:
This code:
Code:
Print PEEK(Uinteger, @b)+2
is supposed to return the 1st string character?

Please, download again the new version (1.2.6-r1603f) from the Archive and try...


Re: String Adress wrong - LCD - 06-19-2010

boriel Wrote:I have a question about your 1st example:
This code:
Code:
Print PEEK(Uinteger, @b)+2
is supposed to return the 1st string character?

Please, download again the new version (1.2.6-r1603f) from the Archive and try...

This should print the address of the memory where the b$ String is stored, without leading bytes. I suppose, the String is stored with size description in the front, and it is not zero-terminated. Proportional print needs the address of the string to be handed over. This is the only way it can be done as POKE STRING address,String does not work. *)
I downloaded the f-version and it works now as it should be. Thank you!

*) Okay, this is not exactly true:
Code:
propprint(0,0,3,1,@textaddress)

textaddress:
asm
  defs "Testtext"
end asm
woulw work somehow too.