----- Original Message ----- From: "Torsten Schoenfeld" <[EMAIL PROTECTED]>
.
.

#ifdef _MSC_VER
# include <stdlib.h>
#endif

#ifdef WIN32
# ifdef _MSC_VER
#  define PORTABLE_STRTOULL(str, end, base) _strtoui64 (str, end, base)
# else
#  define PORTABLE_STRTOULL(str, end, base) strtoul (str, end, base)
# endif
#else
# define PORTABLE_STRTOULL(str, end, base) strtoull (str, end, base)
#endif

guint64
SvGUInt64 (SV *sv)
{
#ifdef USE_64_BIT_ALL
return SvUV (sv);
#else
return PORTABLE_STRTOULL (SvPV_nolen (sv), NULL, 10);
#endif
}

SV *
newSVGUInt64 (guint64 value)
{
#ifdef USE_64_BIT_ALL
return newSVuv (value);
#else
char string[25];
STRLEN length;
SV *sv;

/* newSVpvf doesn't seem to work correctly. */
length = sprintf(string, "%llu", value);
sv = newSVpv (string, length);

return sv;
#endif
}

This seems to work OK on most Unices, but doesn't seem to cut it on
Win32.

It won't compile for me (on either linux or win32). I tried it as an
Inline::C script:

---------------------------------------------
use warnings;
use Inline C => Config =>
   BUILD_NOISY => 1;

use Inline C => <<'EOC';
#ifdef _MSC_VER
# include <stdlib.h>
#endif

#ifdef WIN32
# ifdef _MSC_VER
#  define PORTABLE_STRTOULL(str, end, base) _strtoui64 (str, end, base)
# else
#  define PORTABLE_STRTOULL(str, end, base) strtoul (str, end, base)
# endif
#else
# define PORTABLE_STRTOULL(str, end, base) strtoull (str, end, base)
#endif

guint64
SvGUInt64 (SV *sv)
{
#ifdef USE_64_BIT_ALL
return SvUV (sv);
#else
return PORTABLE_STRTOULL (SvPV_nolen (sv), NULL, 10);
#endif
}

SV *
newSVGUInt64 (guint64 value)
{
#ifdef USE_64_BIT_ALL
return newSVuv (value);
#else
char string[25];
STRLEN length;
SV *sv;

/* newSVpvf doesn't seem to work correctly. */
length = sprintf(string, "%llu", value);
sv = newSVpv (string, length);

return sv;
#endif
}

EOC

print "Compiled\n";
---------------------------------------------

During compilation I get the errors:

_64bit_pl_498e.xs:20: error: syntax error before "SvGUInt64"
_64bit_pl_498e.xs:30: error: syntax error before "value"
_64bit_pl_498e.xs: In function `newSVGUInt64':
_64bit_pl_498e.xs:40: error: `value' undeclared (first use in this function)
_64bit_pl_498e.xs:40: error: (Each undeclared identifier is reported only
once
_64bit_pl_498e.xs:40: error: for each function it appears in.)

I believe the errors arise because the 'guint64' type is uknown. Is there a
missing header ?

I would think we'll also need a typemap that tells perl how to deal with the
guint64 type.

(I have a sneaking suspicion that I've missed something here :-)

As regards runtime errors, something like "%llu" will not be interpreted correctly on Windows 2000 and earlier - you'll want to use "%I64u", "%I64x" and "%I64d". (The same possibly applies to Windows XP - but I haven't checked.) On my Vista 64 box I find that "%llu", "%llx", and "%lld" *are* interpreted correctly (as also are "%I64u", "%I64x" and "%I64d"). Apparently theWindows C runtime has been modified for Vista 64 (and probably Vista 32 as well - again I haven't checked).

Cheers,
Rob

Reply via email to