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

Re^2: [OT(C)] float parameter treated as double by callee -- but it fails with FFI

by vr (Curate)
on Jun 29, 2021 at 17:03 UTC ( #11134455=note: print w/replies, xml ) Need Help??


in reply to Re: [OT(C)] float parameter treated as double by callee -- but it fails with FFI
in thread [OT(C)] float parameter treated as double by callee -- but it fails with FFI

Exactly, in TIFF.xs double is simply cast to float, no issues with that. My confusion was about line 337, where double is expected as argument. But, what I just found in plain Wikipedia:

Another consideration is the default argument promotions applied to the unnamed arguments. A float will automatically be promoted to a double. Likewise, arguments of types narrower than an int will be promoted to int or unsigned int. The function receiving the unnamed arguments must expect the promoted type.

That answers my question about libtiff code. And, perhaps implicitly, addresses the question about FFI: for variadic functions, promoted args types must be specified (i.e. not float, but double). OK, now I'm educated:)

  • Comment on Re^2: [OT(C)] float parameter treated as double by callee -- but it fails with FFI

Replies are listed 'Best First'.
Re^3: [OT(C)] float parameter treated as double by callee -- but it fails with FFI
by syphilis (Bishop) on Jun 30, 2021 at 00:30 UTC
    A float will automatically be promoted to a double

    I wasn't aware of this, either.
    I've eventually located this info in K&R (2nd Edition) in section A7 - "A7.3.2 Function Calls".
    Thanks for spreading the education !!

    Cheers,
    Rob
Re^3: [OT(C)] float parameter treated as double by callee -- but it fails with FFI
by ikegami (Pope) on Jul 01, 2021 at 23:10 UTC

    That's why there's no printf length modifier for char, float or double.

    signed char c = 123; int i = 123; float f = 123; double d = 123; printf("%d\n", i); // ok printf("%d\n", c); // ok, even though %d expects int. printf("%f\n", d); // ok printf("%f\n", f); // ok, even though %f expects double.

    (Not sure why there's one for short since they are guaranteed to be no larger than an int and unsigned int respectively.)

    Seeking work! You can reach me at ikegami@adaelis.com

      There is one for char (hh).

      The reason it and the one for short (h) exists is purely for symmetry with scanf (which needs to know the type of object at the provided address).

      Seeking work! You can reach me at ikegami@adaelis.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134455]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2021-09-17 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?