Pointer and PB 5.11

Just starting out? Need help? Post your questions and find answers here.
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Pointer and PB 5.11

Post by nicolaus »

Hi all,

can any one plz help me with the crasy and not BASIC functionality since PB 5.11?
The follow code works very well in PB 5.00, it was easy to understand and it is working.
Since PB 5.11 the follow sample is not longer working. No sample code is showing in the installation folder of PB 5.11 for the new functionality. There is no sample or detailed "how to" in the help file.

I have try to test different combinations in PB 5.11 but nothing is working for me.

So can you show my, based on my sample, how i must change it to bring it up to work in PB 5.11?

Code: Select all

Procedure test_1(*test1.s)
   strTest.s = "Hello"
   *test1 = strTest
EndProcedure
Procedure Test_2()
   Protected myText.s
   myText = Space(1024)
   test_1(@myText)
   Debug myText
EndProcedure

Test_2()
@PB-Team
Please bring samplers for stuff like this with PB installation and also a detailed help sample.
Neil
Enthusiast
Enthusiast
Posts: 198
Joined: Wed Feb 29, 2012 8:04 am
Location: Melbourne, AUS

Re: Pointer and PB 5.11

Post by Neil »

nicolaus wrote:

Code: Select all

Procedure test_1(*test1.s)
Alexi wrote:Poke it. :D

Code: Select all

Procedure test_1(*test1)
Also note error in Line 1 "Native types can't be used with pointers"
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Pointer and PB 5.11

Post by ts-soft »

This one works on all versions of pb!

Code: Select all

Procedure test_1(*test1.String)
  strTest.s = "Hello"
  *test1\s = strTest
EndProcedure
Procedure Test_2()
  Protected myText.String
  myText\s = Space(1024)
  test_1(@myText)
  Debug myText\s
EndProcedure

Test_2() 
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
buddymatkona
Enthusiast
Enthusiast
Posts: 252
Joined: Mon Aug 16, 2010 4:29 am

Re: Pointer and PB 5.11

Post by buddymatkona »

Here is another POKE-like option.

Code: Select all

Procedure test_1(*test1)
   strTest.s = "Hello"
   CopyMemory(@strTest, *Test1, StringByteLength(strTest)) ; 
EndProcedure
Procedure Test_2()
   Protected myText.s
   myText = Space(1024)
   test_1(@myText)
   Debug myText
EndProcedure

Test_2()
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Re: Pointer and PB 5.11

Post by nicolaus »

ts-soft wrote:This one works on all versions of pb!

Code: Select all

Procedure test_1(*test1.String)
  strTest.s = "Hello"
  *test1\s = strTest
EndProcedure
Procedure Test_2()
  Protected myText.String
  myText\s = Space(1024)
  test_1(@myText)
  Debug myText\s
EndProcedure

Test_2() 
Thanks @ts-soft!
i think this change from PB5.00 to PB5.11 is a step back.
In my opinion, this is from BASIC to COMPLEX.
User avatar
skywalk
Addict
Addict
Posts: 4219
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Pointer and PB 5.11

Post by skywalk »

I disagree.
As ts-soft said, the structure method would have worked in PB versions going way back before v5.0. Same with Poke().
So, really, it is just a Basic "misunderstanding" given the documentation is not as thorough as this forum. :idea:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Pointer and PB 5.11

Post by helpy »

nicolaus wrote:The follow code works very well in PB 5.00, ...
It can be, that the example code works will, but the use of *variable.s sometimes cuase unpredictable results, errors or crash of an program.

Here a little test code:

Code: Select all

EnableExplicit

CompilerIf #PB_Compiler_Debugger = #False
	Procedure ErrorHandler()
		MessageRequester("OnError test", "The following error happened: " + ErrorMessage())
	EndProcedure
	OnErrorCall(@ErrorHandler())
CompilerEndIf

Procedure test_1(*test1.s)
	Static count
	Protected strTest.s
	count = count + 1
	strTest.s = "Hello " + RSet(Str(count), 10, "0")
	*test1 = strTest
	ProcedureReturn count
EndProcedure
Procedure Test_2(*test2.s)
	Protected count
	Protected myText.s
	myText = Space(1024)
	count = test_1(@myText)
	*test2 = myText
	ProcedureReturn count
EndProcedure


Define i, test.s, count, sLength

MessageRequester("","TEST START")

sLength = Len( "Hello 0123456789" )
For i = 1 To 1000000
	test.s = Space(1024)
	count = Test_2(@test) 
	; 	Debug test
	If Len(test) <> sLength
		MessageRequester( "", "ERROR at loop " + Str(count) )
		End
	EndIf
Next i

MessageRequester("","TEST DONE")
Results in Windows 8 64 Bit with PureBasic 5.00:
  • PureBasic 5.00 x86 with debugger: wrong result at loop 6
  • PureBasic 5.00 x86 without debugger: wrong result at loop 6
  • PureBasic 5.00 x64 with debugger: program crashes and debugger returns message: "The debugged executable quit unexpectedly"
  • PureBasic 5.00 x64 without debugger: program crashes without any message
Conclusion: The use of *variable.s is leads to unstable programs

cu,
guido
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
Post Reply