PB5.50B1 : Little Question to @Constant$

Everything else that doesn't fall into one of the other PB categories.
User avatar
Bisonte
Addict
Addict
Posts: 1324
Joined: Tue Oct 09, 2007 2:15 am

PB5.50B1 : Little Question to @Constant$

Post 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 ?
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

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

Post 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.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 318
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

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

Post 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
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

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

Post 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:
Last edited by DontTalkToMe on Sat Jun 11, 2016 11:51 pm, edited 1 time in total.
User avatar
skywalk
Addict
Addict
Posts: 4264
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post 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$
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Derren
Enthusiast
Enthusiast
Posts: 318
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

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

Post 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^^
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

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

Post 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 .... :)
Fred
Administrator
Administrator
Posts: 18396
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

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

Post 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.
sq4
User
User
Posts: 98
Joined: Wed Feb 26, 2014 3:16 pm
Contact:

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

Post 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.
User avatar
Bisonte
Addict
Addict
Posts: 1324
Joined: Tue Oct 09, 2007 2:15 am

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

Post 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...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Post Reply