ingydotnet / inline-c-pm

10 stars 19 forks source link

Return type of `long long` not recognised #105

Open mohawk2 opened 6 months ago

mohawk2 commented 6 months ago

This failed:

use strict;
use warnings;
use Inline C => <<'EOF';
long long as_int(double d) {
  double d1 = d;
  long *p = (long *)&d;
  return *p;
}
EOF

my $arg = 1.69883998968099e-313;
printf "%30.30g = %016x\n", $arg, as_int($arg);

While deleting the first long made it succeed.

sisyphus commented 6 months ago

There's no ExtUtils/typemap entry for 'long long'. The best thing to do would be to submit a PR to https://github.com/Perl/perl5 that addresses this shortcoming. Other than that you could provide your Inline::C script with its own (correcting) typemap, or even patch your perl's ExtUtils/typemap appropriately. In my own case, this patch to ExtUtils/typemap was all that I needed:

--- typemap_orig        2023-11-27 23:57:47.000000000 +1100
+++ typemap     2024-03-28 10:59:44.139057400 +1100
@@ -4,6 +4,8 @@
 unsigned int           T_UV
 long                   T_IV
 unsigned long          T_UV
+long long                      T_IV
+unsigned long long             T_UV
 short                  T_IV
 unsigned short         T_UV
 char                   T_CHAR

but I'm not so sure about the overall portability of that solution.