syphilis has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
In an XS file I have the following line of code:
This is normally achieved by assigning an appropriate value to DEFINE in the WRITEMAKEFILE() section of the Makefile.PL - eg:
Update: By "not work", I mean that it either won't compile or it leads to runtime crashes (depending upon the actual incantation I've tried).
Any help would be much appreciated.
I've also spent a couple of hours trying to get this working in Inline::C. If I can get it to work in Inline::C, then I'll be able to use the incantation in the Makefile.PL that Inline::C generates.
Here's that Inline::C script:
In C, it's pretty simple to achieve:
Cheers,
Rob
In an XS file I have the following line of code:
I want to rewrite that line as:printf("%.16e", sqrt(2.0));
I also wish to then define MY_FORMAT to "%.16e" in the Makefile.PL.printf(MY_FORMAT, sqrt(2.0));
This is normally achieved by assigning an appropriate value to DEFINE in the WRITEMAKEFILE() section of the Makefile.PL - eg:
But that specific incantation fails to work - and I haven't been able to hit on the incantation that *does* work.WRITEMAKEFILE( .... DEFINE => '-DMY_FORMAT="%.16e"', .... );
Update: By "not work", I mean that it either won't compile or it leads to runtime crashes (depending upon the actual incantation I've tried).
Any help would be much appreciated.
I've also spent a couple of hours trying to get this working in Inline::C. If I can get it to work in Inline::C, then I'll be able to use the incantation in the Makefile.PL that Inline::C generates.
Here's that Inline::C script:
I've tried various escapes around "%.16e" but nothing has been successful.use strict; use warnings; use Config; use Inline C => Config => USING => 'ParseRegExp', CCFLAGSEX => '-DMY_FORMAT="%.16e"', BUILD_NOISY => 1, ; use Inline C =><<'EOC'; SV * foo(void) { printf(MY_FORMAT, sqrt(2.0)); printf("\n"); } EOC foo();
In C, it's pretty simple to achieve:
I'm not all that bothered if it turns out that Inline::C can't handle the construct, but I *would* like to know how to do it in the XS file via the Makefile.PL if, indeed, that's possible at all.C:\_32\C>type try.c #include <stdio.h> #include <math.h> int main(void) { printf(MY_FORMAT, sqrt(2.0)); return 0; } C:\_32\C>gcc -o try.exe try.c -DMY_FORMAT=\"%.16e\" C:\_32\C>try 1.4142135623730951e+000 C:\_32\C>
Cheers,
Rob
|
---|
Back to
Seekers of Perl Wisdom