Page 1 of 1

PB5.50B1 : Little Question to @Constant$

Posted: Sat Jun 11, 2016 9:22 pm
by Bisonte
Hello...

As i read in the announcement :

Code: Select all

- Added: @#StringConstant$ syntax support, to get the address of a string constant
I ask me one Question :

"What happens if someone do this ?"

Code: Select all

#StringConstant$ = "Hello"
PokeS(@#StringConstant$, "PureBasic")
Debug #StringConstant$
Legal ? Memory Errors (cause the poked string is longer/shorter..) ?

Is this a bug or a feature ?

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sat Jun 11, 2016 10:37 pm
by DontTalkToMe
Variable constants are a reality finally. PB is pushing the boundaries :D

Code: Select all

#StringConstant$ = "Hello"
#Horror$ = "Horror"

Debug #StringConstant$
Debug #Horror$


PokeS(@#StringConstant$, "PureBasic")

Debug #StringConstant$
Debug #Horror$
The offset of #Horror$ is constant (just after the end of the original #Hello$ ) and so the result is what you would expect.

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sat Jun 11, 2016 11:39 pm
by Derren
I need to get me the beta soon, this looks "interesting".

What about this? oO

Code: Select all

#const$ = "hello"
Dim myArray.i(10)
For i = 0 To 10
  myArray(i) = i * (10000) + 999
Next
PokeS(@#const$, "PureBasic Beta Stuff")

For i = 0 To 10
  Debug myArray(i) 
Next

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sat Jun 11, 2016 11:47 pm
by DontTalkToMe
What about it ?
I need to get me the beta soon, this looks "interesting".
If you didn't have the beta, how can you test the above code ? :shock:

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sat Jun 11, 2016 11:50 pm
by skywalk
Kinda confusing? #World$ does not always appear next to #Hello$ in the memory viewer?

Code: Select all

#Hello$ = "Hello"
#World$ = "World"
Debug "#Hello$ = " + #Hello$
Debug "#World$ = " + #World$
ShowMemoryViewer(@#Hello$-128, 256)
;Debug @#Hello$ ;<-- Without these, #World$ does not appear in Memory Viewer?
;Debug @#World$ ;<--
CallDebugger
Debug "PokeS(@#Hello$, '12345', 5, #PB_String_NoZero)"
Debug PokeS(@#Hello$, "12345", 5, #PB_String_NoZero)
ShowMemoryViewer(@#Hello$-128, 256)
Debug "#Hello$ = " + #Hello$
Debug "#World$ = " + #World$

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sun Jun 12, 2016 12:45 am
by Derren
DontTalkToMe wrote:What about it ?
I need to get me the beta soon, this looks "interesting".
If you didn't have the beta, how can you test the above code ? :shock:
I can't. That's why I asked^^

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sun Jun 12, 2016 1:01 am
by DontTalkToMe
Looked like you were saying "see what this program does!" oO
In that case, your program runs fine for what I can see.
If you were expecting for the array to be overwritten, that doesn't happen.
If that's what you were thinking because you didn't say.
oh well .... :)

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sun Jun 12, 2016 6:44 am
by Fred
Bisonte wrote:Hello...

As i read in the announcement :

Code: Select all

- Added: @#StringConstant$ syntax support, to get the address of a string constant
I ask me one Question :

"What happens if someone do this ?"

Code: Select all

#StringConstant$ = "Hello"
PokeS(@#StringConstant$, "PureBasic")
Debug #StringConstant$
Legal ? Memory Errors (cause the poked string is longer/shorter..) ?

Is this a bug or a feature ?
It's the same as patching a literal string constant: you can do it, but it's strongly not recommanded.

Code: Select all

PokeS(@"Hello", "World")
Debug "Hello" ; Wooooot
To avoid this, we could put the literal string datasection in read only so it would raise a IMA, but I don't know if it worths it.

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sun Jun 12, 2016 8:17 am
by sq4
Fred wrote: To avoid this, we could put the literal string datasection in read only so it would raise a IMA, but I don't know if it worths it.
Please don't. It would break backward compatibility.

Re: PB5.50B1 : Little Question to @Constant$

Posted: Sun Jun 12, 2016 9:14 am
by Bisonte
Fred wrote: To avoid this, we could put the literal string datasection in read only so it would raise a IMA, but I don't know if it worths it.
This is not necessary !

I only wanted to know, what happened... so we have NOT! do something like that...