Equivalence in variables addresses

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

Hi,

I am having a guess about the best way to make two variables, even of different types, having the same start address.

Some years ago I was designing Fortan apps using Equivalence keyword which allow to make ie the following :

Dim text[1000] as string * 1 (means a 1000 single characters text array)
Dim array[1000] as byte (means a 1000 single bytes array)
Equivalence text, array

From there you can either look at text or array at the same address.

How would one here do the same to make a fixed start address for both variables in good regular PureBasic coding ?

KRgds

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Pointers are here for that :)

For example:

Code: Select all

Structure Byte
  b.b
EndStructure

Text$ = "HELLO"

*Cursor1.Byte = @Text$
*Cursor2.Byte = @Text$

Repeat
  Debug Chr(*Cursor1\b) : *Cursor1+1
  Debug Chr(*Cursor2\b) : *Cursor2+1
Until *Cursor1\b = 0


Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.

You could also create a union for a more general case of variables occupying the same memory locations.

--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.30)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

Thanks a lot for this. I will make tests and take profit of it.

KRgrds

Francois Weil
14, rue Douer
F64100 Bayonne
Post Reply