Thanks Anonymonk, the bytes most definitely have individual meaning... MSByte is a control register (which actually consists of two 4-bit nibbles, but I dissect that later in the chain), and LSByte is the data register, both of a larger 16-bit command register, which gets sent to a piece of hardware over the Serial Peripheral Interface.

Example of what I was originally toying with:

# perl testing(65535, 4); ... // C #include <stdio.h> int testing(int n, int len){ unsigned char bytes[4]; bytes[3] = (n >> 24) & 0xFF; bytes[2] = (n >> 16) & 0xFF; bytes[1] = (n >> 8) & 0xFF; bytes[0] = n & 0xFF; printf("output should be 255, 255, 0, 0\n\n"); printf("%d, %d, %d, %d\n", bytes[0], bytes[1], bytes[2], bytes[3]) +; return 0; }

Works fine. The problem though is that the buf array is eventually sent to another C function that puts it on the SPI bus. The way I've done it in the above example limits me to accept/send only a single 4-byte array, so if a device requires say 6 bytes, I'd have to add in another param (at least that's how I saw it). I wanted my Perl code to be as compatible with the API I'm using as possible, and heck, I've always wanted to learn how to pass in an array/aref to a C function anyway, so it was a fun learning experience :)


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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.