Nitin Madnani wrote:
Hi Everyone

First, I want to thank all you guys for all the great advice in the past !!

Here's another question :

I can use a double in perl as a hash key and perl automatically converts it to a string and uses it right? How do I do the same in my C code, i.e,

I have this in perl space:

$x = -1e100;

..... some mathematical manipulations on $x

$hash{$x}++;

I have the equivalent double 'x' in my C code. And I want to check whether the key 'x' exists in the hash. For that I need to explicitly convert 'x' to a string value, correct? How do I do that ?


In addition to the answers you've received already, there's also a way of doing it that makes use of the same duplicity that perl exploits:


use warnings;
use strict;

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

use Inline C => <<'EOC';

void foo(SV * a) {
     double d = (double)SvNV(a);
     char * str = (char *)SvPV_nolen(a);

     printf("%f %s\n", d, str);
}

EOC

my $double = 1234.78901;
foo($double);

__END__

Cheers,
Rob



Reply via email to