pointer to constant string?

Just starting out? Need help? Post your questions and find answers here.
bosker
Enthusiast
Enthusiast
Posts: 105
Joined: Fri Jan 08, 2010 11:04 pm
Location: Hampshire, UK

Re: pointer to constant string?

Post by bosker »

There's no loop used in intialisation. In my example (and Trond's), the loop is just a demonstration that the array is set up.
It's the *MyPtr.SArray = ?MyData that does the setup.

The ! at the start of a line means the PB compiler passes these through to the assembler, ie these are assembler lines.
The strptr macro is a FASM macro that sets up the string array for you (I have it defined in an include file).
Basically it creates a data structure that contains pointers to each of the strings passed to it so you end up with...

MyData:
<pointer to string 1>
<pointer to string 2>
... etc ...

<string 1 data, 0>
<string 2 data, 0>
.. etc ...

The thing at MyData is therefore the string array. If you want to use the pointers to these preset strings, just overlay another data structure at the same place or use a union as Trond's example.

Part of the power of PB is the ease of use of assembler - and it's possible to get pointers to anything you want with that.

Looking at your original post - the first call of the testing function works for me (even though it's not officially supported).
The PB guaranteed way to do this would be...

Code: Select all


Procedure TestingPointers2(*s)
   Debug "Doing Pointers S :" + PeekS(*s)
   Debug *s
EndProcedure

TestingPointers2(@"CONSTANT")

User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: pointer to constant string?

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply