This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/32448] abs / printf bug
- From: "rob1weld at aol dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Jun 2007 12:22:05 -0000
- Subject: [Bug c/32448] abs / printf bug
- References: <bug-32448-13830@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #21 from rob1weld at aol dot com 2007-06-24 12:22 -------
(In reply to comment #20)
> > Since GCC can 'see' the "%f" at compile time
> ... that does not mean the behavior is the correct to cast it to float. ...
So the correct behavior is:
a): Cast it to something other than float.
- if it can only be float (in the example, otherwise anything else) as far as
printf is concerned then why do that? I know you are NOT suggesting that we
could cast it to (int) and use "%f" to print it and you are NOT suggesting
that we could cast it to (char *), a string, and print it with "%f".
- If the printf contains "%f" then the var "must" be a float.
Example:
long double A = 123.456;
int B = A;
Is the variable B an int, or something else. Why is it incorrect behaviour to
print it with %f even if that means we get (a compiler warning when compiling
and) 123.000 for output - would anyone prefer gibberish for output ?
b): do as I suggested and avoid the security issue, bad output, and the need
for contorted code (as shown in comment #18).
c): The Emperor's clothes look wonderful.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32448