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

Re: [XaraXtreme-dev] Doubles and Strings



In message <44D32D12.7020508@xxxxxxxxxxx>
          Alex Bligh <alex@xxxxxxxxxxx> wrote:

> Martin Wuerthner wrote:
>> 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.
> 
> camScanf works through varags, it's actually vswscanf that gets called,
> with an argptr, so no opportunity for compile-time checks. That's
> because wxFormatConverter gets in the way to convert (say)
> %s to %ls, so the format string is the same on Unicode and non-Unicode.
> 
> Are you *SURE* %lf is undefined for output versions? That's really
> very annoying especially as I've just converted them all over. I
> thought superfluous size qualifiers were meant to be discarded...

No, I am not sure, but I have not seen any information either way. In 
any case, "l" does not have any defined meaning when applied to "f" 
for input (though "L" does for long double), but I have not seen any 
statement about what happens when you supply that combination. While 
it is reasonable to expect that superfluous size qualifiers are 
ignored, I have not seen any definitive statement to this effect. As 
far as my literature (K&R and Stroustrup) goes, it is only "undefined" 
in the sense that its meaning has not been defined, not in the sense 
that it has been explicitly declared undefined (you need to be a 
language lawyer to appreciate the difference). I guess, the ISO 
standard will have something to say about it.

Martin