[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

Re: [XaraXtreme-dev] Doubles and Strings



In message <44D32131.6030509@xxxxxxxxxxx>
          Alex Bligh <alex@xxxxxxxxxxx> wrote:

> The correct way to pass a double as a parameter to sprintf, sscanf etc.
> is using "%lf" not "%f" (which means float). This is the reason many
> things (including all EPS import) do not currently work on any platform
> where float != double.

Just for the sake of correctness: You mentioned both sprintf and 
sscanf above, which is wrong. What you wrote applies to the scanf 
family of routines only (i.e., just to input, not to output).

When using sprintf et al., "%f" means double and "%lf" is undefined. 
The reason is some arcane bit of C semantics that causes the supplied 
value argument to be promoted to double anyway, so it does not make 
any difference whether you pass a float or a double. For obvious 
reasons, argument promotion does not apply to pointers, so the scanf 
family of routines has to distinguish between float and double. A good 
compiler checks the format string and the supplied pointer types and 
issues a warning if they do not match. I was under the impression that 
GCC does that.

Martin