|Do you know where your variables are?|
Inline::C producing an absurd resultby syphilis (Chancellor)
|on May 08, 2017 at 01:28 UTC||Need Help??|
syphilis has asked for the
wisdom of the Perl Monks concerning the following question:
This demo script requires a compiler (eg gcc) that provides the _Decimal64 type:
which tells me that -0 != 0 (and that is contrary to IEEE standards).
However, if I copy'n'past that C code across to a separate file and run it as a C program (using the very same compiler) I get correct output:
AFAICS, all that has changed is that "foo" has been renamed to "main".
Yet, this now correctly outputs:
I'm seeing this behaviour on both Windows and Linux for a variety of perl versions and a variety of gcc compilers from 4.7.0 to 7.1.0 - so I'm hopeful that anyone else who has a gcc-4.x.x compiler (or later) will have no trouble reproducing the behaviour. Only other thing needed is Inline::C.
I've gazed upon the C code that Inline::C generates, and I've run the script through the C pre-processor, but I haven't managed to spot anything that helps me understand how this anomaly exists.
I've also spent some time trying various things that I hoped might trick Inline::C into behaving properly and I did find that this works:
All I've done there is to move the test that foo() was previously doing, into a separate sub. That produces correct output of:
Unfortunately the same approach doesn't work for the _Decimal128 type, where the same issue also arises.
There's nothing of much immediate importance with this ... but I can't stop scratching at it ;-)
Your insights are most welcome