For the typemap you need to add typemap entries that map your types to the same as the other int types, eg. in typemap:

gf2_u8 T_UV gf2_u16 T_UV gf2_u32 T_UV gf2_s8 T_IV gf2_s16 T_IV gf2_s32 T_IV

ExtUtils::MakeMaker should pick up the type map automatically when you run Makefile.PL.

As to whether those types are the correct types, one possibility is stdint.h, which requires a C99 compiler/libc, but in most cases, if the C compiler has 8 and 16 bit int types, char and short will be them.

Unfortunately perl doesn't probe for stdint.h, so it's something you'd need to probe for yourself.

For 32-bit, long might be 64-bit*, so in the absence of inttypes.h you could use limits.h:

#include <limits.h> #if USHRT_MAX > 0x80000000 typedef unsigned short gf2_u32; #elif UINT_MAX > 0x80000000 typedef unsigned gf2_u32; #else typedef unsigned long gf2_u32; #endif

* According to the standard, they could all be 128-bit, but most likely char is 8 bit if the compiler has an 8-bit type, and unless the compiler has stdint.h, short will be the 16 bit type if there is one.


In reply to Re: A clean way to account for machine word sizes in XS code? by tonyc
in thread A clean way to account for machine word sizes in XS code? by dec

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.