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

NativeCall Doc booboo

Thread Next
Todd Chester via perl6-users
December 31, 2019 04:54
NativeCall Doc booboo
Message ID:
Hi All,

Did anyone else discover the mistake, hopefully not the hard way like I
did.  Anyone get weird gibberish printed out like I did?

    # The lifetime of this variable must be equal to the required lifetime of
    # the data passed to the C function.

The mistake is that "C" strings are terminated by a chr(0) -- in
"C" terms chr(0) is called a nul or 0x00.

If you don't terminate your C string, the reading functions keep careening
until it finds a chr(0).  You have to tack a chr(0) onto the end.

    $array [$array.elems] = 0;

$array should be 70 79 70 0  not  70 79 79
You can test this with `say "$array"` (include the quotes).

Maybe JJ will pick up on this and get it fixed.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About