Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found