develooper Front page | perl.perl6.users | Postings from December 2022

pointer confusion

Thread Next
From:
ToddAndMargo via perl6-users
Date:
December 3, 2022 11:44
Subject:
pointer confusion
Message ID:
4be27a3f-dac3-77c8-cdf1-c2301139adf4@zoho.com
Hi All,

NativeCall question:

I am confused about how to assign an address
to a pointer


[1] > use lib '.'; use NativeCall; use NativeConstants
Nil


[2] > my $x=0xFE45DDCC;
4265991628


[3] >  my Pointer $Ptr2Ptr  = NativeCall::Types::Pointer[BYTES].new($x);

NativeCall::Types::Pointer<0xfe45ddcc>


[4] > print "x = <" ~ $x ~ "> <0x" ~ $x.base(16) ~ ">   Ptr2Ptr <" ~ 
$Ptr2Ptr ~ ">\n";

x = <4265991628> <0xFE45DDCC>   Ptr2Ptr 
<NativeCall::Types::Pointer<4852306736864>>


[5] > dd $Ptr2Ptr
Pointer $Ptr2Ptr = NativeCall::Types::Pointer.new(4265991628)
Nil


[6] > say $Ptr2Ptr
NativeCall::Types::Pointer<0xfe45ddcc>




Here is the confusion.  In step [3], when
I created the pointer ($Ptr2Ptr), I pre-salted
$Ptr2Ptr with $x (0xFE45DDCC), REPL showed
$Ptr2Ptr was created with the value of $x.

But in step [4], when I printed out the value
of $Ptr2Ptr, is some other number and not $x.

And steps [5] and [6] comes out okay.


What am I missing?  What is wrong with step [4]?

Yours in confusion,
-T


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About