[OPEN-ILS-DEV] C nits: invalid conversion specification
Joe Atzberger
atzberger at MECDC.ORG
Mon May 7 13:52:08 EDT 2007
Perl accepts it inasmuch as it doesn't consider it an error (even under warnings and strict). The typical error message
would be (for example, with %j):
Invalid conversion in printf: "%j"
I agree there doesn't seem to be any reason to use "%lf" in perl either, since apparently all floating point formatting
gets handed off to the C sprintf.
--Joe
Scott McKellar wrote:
> What is your basis for saying that Perl accepts "%lf" for printf
> and sprintf?
>
> I looked at the link you provided, and I looked in the camel book
> (which has much of the same verbiage), and I don't see any indication
> that "%lf" is valid in Perl.
>
> Given that Perl relies on the C library to format floating point
> numbers, one of three things must be happening:
>
> 1. Perl silently removes the extraneous 'l' before passing the
> conversion specification to the C library, or:
>
> 2. It doesn't, and whatever happens happens, depending on what the
> C library does on a give platform, or:
>
> 3. It issues an error or warning message, and possibly takes either
> of the above actions as well.
>
> I just experimented with a test script using "%lf" and perl didn't
> complain, even with the -w option. So the third possibility above
> appears not to be happening.
>
> In any case, it seems like there's no good reason to use "%lf" in
> Perl, any more than in C.
>
> Disclaimer: my knowledge of Perl doesn't extend much beyond how to
> spell it.
>
> Scott McKellar
> http://home.swbell.net/mck9/aargh/
>
>
> --- Joe Atzberger <atzberger at MECDC.ORG> wrote:
>
>> Perl accepts "%lf" as an accepted format for printf and sprintf. It
>> would only be particularly meaningful on a system
>> where the default size of a floating point number was not long double
>> (i.e., double or quad).
>>
>> From perldoc:
>> http://perldoc.perl.org/functions/sprintf.html
>> "For floating point conversions (e f g E F G), numbers are usually
>> assumed to be the default floating point size on
>> your platform (double or long double), but you can force 'long
>> double' with q, L , or ll if your platform supports them."
>>
>> Interestingly, this may conflict with the fact that perl's sprintf
>> actually invokes the C version for floating point
>> numbers:
>> "Perl does its own sprintf formatting--it emulates the C function
>> sprintf, but it doesn't use it (*except for
>> floating-point numbers*, and even then only the standard modifiers
>> are allowed)."
>>
>> So based on that, I'm more confused than anything. It seems like it
>> should only be a question of what the C version
>> supports for floats, even if perl doesn't report a warning/error.
>>
>> --Joe Atzberger
>> INFOhio Technical Specialist
>> Metropolitan Educational Council
>> (614) 473-8300 x22
>> atzberger at mecdc.org
>
> <snip>
More information about the Open-ils-dev
mailing list