Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Thanks tye, that's great!

I was trying similar things, but did not realize pack was required. This is far easier and less error-prone as you said (as well it saves me from having to wrap one C function with another as this way, I can pass the data directly to the original function), but I am thankful that I was able to learn how to pass in perl variables into a C function, even though I'm going to revert to using this method instead:

use warnings; use strict; use feature 'say'; use Inline 'C'; my @b = (1..3, 253..255); my $x = pack "V0C*", @b; check($x, length($x)); __END__ __C__ #include <stdio.h> #include <stdint.h> void check(unsigned char* n, int len){ int i; for(i=0; i<len; i++){ printf("%d\n", n[i]); } }


1 2 3 253 254 255

Of course, in the real code, I perform error checking.

In reply to Re^2: Is this a sane/safe way to pass an aref into a C function? (XS<Perl) by stevieb
in thread Is this a sane/safe way to pass an aref into a C function? by stevieb

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2022-08-10 10:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found