avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] %f


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] %f
Date: Tue, 10 Oct 2006 10:50:03 +0200
User-agent: Mutt/1.5.11

As Steve Franks wrote:

> I know no one else in their right mind uses floating point
> printf/scanf.

Why not?

> That said, the "double format, float arg" warning is a
> bit tedious (when you have a giant string parser in a mega128).

It's only tedious as the AVR currently doesn't support 64-bit doubles,
so sizeof(float) == sizeof(double).  Applying the correct type casts
is thus a matter of ``living to the letter of the standard'' without
having any practical impact.

> Wouldn't the correct notation be %f -> float; %lf -> double?

No, it wouldn't.  You cannot pass a float in a variable argument list,
because the elements of a variable argument list are subject to
default argument proomotion, where each float value will be promoted
to double.  You are supposed to cast it to (double) to make this
explicit (to the brain of the developer) -- that's what the warning is
telling you.

> I further notice %f is a double in printf, but a "pointer to float"
> in scanf.

Yes, it is.  %lf denotes a pointer to double in scanf().  %lf is
identical to %f in printf().

> Has this been addressed already?

Yes, it has.  By the C standard, section 7.9.16.1 (fprintf), and
7.9.16.2 (fscanf), and 6.5.2.2 (function calls, that's where the
argument promotion is described).

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]