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