Change of Pointer-Type

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Change of Pointer-Type

Post by GPI »

At the moment we must write this:

Code: Select all

long.l
*pointer=@long
*long.long=*pointer
*long\l=10
Ok, the example is a little bit stupid, but sometimes you must change the type of the pointer like above. At the moment we must create a new one and copy the adress to the new pointer.
My suggestion:

Code: Select all

long.l
*pointer=@long
(*pointer).*long\l=10
;the star is here important, because it indicate a pointer.

Other possibilities to use this:

Code: Select all

Structure duo
  StructureUnion 
    q.q
    d.d
  EndStructureUnion
EndStructure

double.d=10.2
Debug Hex( (double).duo\q ); should be "4024666666666666"
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Change of Pointer-Type

Post by STARGÅTE »

I think, in your cases it is easier, to use Peek and Poke:

Code: Select all

long.l
PokeL(@long, 10)

Code: Select all

double.d=10.2
Debug Hex( PeekQ(@double) )
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply