Documentation for the libtiff tag setter function says that TIFFTAG_XRESOLUTION tag must be passed as float value. Code examples I see elsewhere (e.g. XS code for Graphics::TIFF), tutorials/examples on the web, SO answers, etc., as well as my own C tests show that, yes indeed, resolution is to be passed as float, and it all works as expected.

However, reading source, I see that callee treats it as double (only to convert it to float a few lines below). First surprise is why the heck and how it works. Even if values on stack are aligned to more than 4 bytes, these are not integers, and packed float value is not a substring of packed double value, is it?

I dug it all up, because I was writing FFI binding for aforementioned tag setter function. I tried different modules: FFI::Platypus, FFI::Raw (though both are libffi based), and they fail to set resolution tag, if I describe parameter as "float". Rather, tag is set to 0, regardless of parameter, function call itself doesn't fail. But, if parameter is described as "double", tag is set as expected (I'll post SSCCE if required).

So, looks like no problem, I have working code, which is temporary prototype anyway, but I'm confused. Even if I feel brave enough to ask libtiff people "maybe you have a bug?", they'd say "all code using libtiff in whole world works fine. What's FFI::Platypus and why would we care?"


In reply to [OT(C)] float parameter treated as double by callee -- but it fails with FFI by vr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.