So, what I'm looking for is an easy way to figure out which native C types have 8, 16 and 32 bits apiece at compilation time and to have my C/XS code use those data types.

Not sure that it's all that easy, but one way would be to have the Makefile.PL determine the sizes of the various types, and then use that info to construct the various typedefs. The ones that will interest you are:
$Config{shortsize}
$Config{intsize}
$Config{longsize}
$Config{ivtype}
and
$Config{ivsize}

Not sure of how to determine charsize. The first 3 give you info about the sizes of the different types for the particular compiler, the last 2 give you the info about the size of the IV (the perl integer).

Depending upon what those values are, you can have WriteMakefile() pass a define symbol to the build process (look for the DEFINE documentation in ExtUtils::MakeMaker), and have the header file write the appropriate typedefs based upon which symbol was defined:
#ifdef some_symbol // one set of typedefs #endif #if def another_symbol // another set of typedefs #endif . .
I do pretty much this in Math::MPFR. I'm essentially looking only at $Config{nvsize} and $Config{ivsize} and I doubt that my approach is infallible, but it seems to work ok - afaik the failures I get there are for other reasons (most of which I don't really care about).

Cheers,
Rob

In reply to Re: A clean way to account for machine word sizes in XS code? by syphilis
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.