#! perl -slw
use strict;
use Inline C => Config => BUILD_NOISY => 1;
use Inline C => <<'END_C', NAME => 'Endian', CLEAN_AFTER_BUILD =>0;
SV *hexDump( UV in ) {
int i;
char *p = (char*)∈
SV *out = newSVpvn( "?", 1 );
for( i=0; i<8; ++i ) {
sv_catpvf( out, "%02x", p[i] );
}
return out;
}
END_C
print hexDump( 72623859790382856 );
__END__
C:\test>endian
?0807060504030201
Which I guess means that the doc for newSVpvn() that reads:"If the s argument is NULL the new SV will be undefined. means something different to what I took it to mean.
This also works: SV *hexDump( UV in ) {
int i;
char *p = (char*)∈
SV *out = newSVpvn( "", 0 );
for( i=0; i<8; ++i ) {
sv_catpvf( out, "%02x", p[i] );
}
return out;
}
|