Note that there are some explanatory texts on larger screens.

plurals
  1. POXS-Module confusion between char * and char[N]
    primarykey
    data
    text
    <p>today i tried to create my first Perl-Module with some C-Bindings. But i ran into some troubles with typedefs and array-notation vs. stright pointers (at least thats what i think, where the trouble comes from).</p> <p>The C-Code in question is a USB-DMX-Interface with an open driver which can be found on <a href="https://github.com/fx5/usbdmx" rel="nofollow">github</a>.</p> <p>I followed the instructions i found in perlxstut and the documentation of h2xs ("<a href="https://metacpan.org/module/RJBS/perl-5.16.2/utils/h2xs.PL#Extension-based-on-.h-and-.c-files" rel="nofollow">Extension based on .h and .c file</a>"</p> <p>But i get some wired "cast specifies array type" and "cast specifies function type" errors from GCC (Version 4.7.2).</p> <p>I could find out, that it has to do with the typedefs of TSERIAL and TSERIALLIST in <a href="https://github.com/fx5/usbdmx/blob/master/usbdmx.h#L9" rel="nofollow">usbdmx.h:Line 9,10</a></p> <p>As far as i can remeber this C-Stuff, Line 9 defines an alias for an char-Array with predefined size of 16. While in Line 10 an alias will be made for an Array of Char Arrays with 32 of those (so 16*32 bytes will be allocated). So in general, without the Array-Initialization there are only char * or char **.</p> <p>When i try to replace these typedef with</p> <pre><code>typdef char * TSERIAL; typdef TSERIAL * TSERIALLIST; </code></pre> <p>things seem to pass on. But then of course it SegFaults when actually running the code, because the memory has never been allocated.</p> <p>So can anybody give me some advice on how to go on with "predefined char-array typedef" and XS-Code in Perl? :)</p> <p>I also could reproduce these troubles with a little C-Testheader:</p> <pre><code>typedef char * NAME; </code></pre> <p>will be listed in "typemap" as "NAME T_PV" after running the h2xs stuff while </p> <pre><code>typedef char NAME[10]; </code></pre> <p>will be listed as "NAME T_PTROBJ" int the typemap.</p> <p>Thanks for your help! :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload