Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Zlatko Vid on March 25, 2024, 09:38:45 PM

Title: Pointers and type casting
Post by: Zlatko Vid on March 25, 2024, 09:38:45 PM
Hi Charles ..All  :)

is this only way to cast float variable in o2 ?
using in this case dereferece * ...

float n
'INT i at strptr s  ' integer pointer cast string s
n = 3.14
sys *p = @n
float f2 = (float)p

print f2

I am looking in all examples ...functionPointers 1 and 2
and not understand it well
like in old EBasic where is used :

print *<float>p

is that syntax even possible in o2
if you ask me i am fine with (float)

but above looking more fancy ...?

Title: Re: Pointers and type casting
Post by: Charles Pegge on March 25, 2024, 10:31:11 PM
Hi Aurel,

This shows the o2 syntax alternatives for casting pointers:

'casting pointers
=================
float n = 3.14
sys p = @n
float f2
f2 = (float*) p
print str(f2,2)
print str((float*)p,2)
print str(cast(float*)p,2)
print str(cast float*p,2)

Title: Re: Pointers and type casting
Post by: Zlatko Vid on March 25, 2024, 11:30:03 PM
Thanks Charles

but why this one work

sys *p = @n

i just tried ..i don't know that work or
simply i expected that not work ...
because of dereferencing  symbol *

of course this looks better:
f2 = (float*) p

Title: Re: Pointers and type casting
Post by: Charles Pegge on March 25, 2024, 11:45:53 PM
sys *p=@n  won't work on the current system. Too much referencing! Just use plain p as  a variable that contains the address of n