public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "adrian.hawryluk at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/46908] New: printf not handling printing of double correctly in certain cases
Date: Sun, 12 Dec 2010 16:12:00 -0000	[thread overview]
Message-ID: <bug-46908-4@http.gcc.gnu.org/bugzilla/> (raw)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46908

           Summary: printf not handling printing of double correctly in
                    certain cases
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: adrian.hawryluk@gmail.com
              Host: Windows XP SP2
            Target: mingw32
             Build: 4.5.0


This is a weird one.  Under different compile options, it does it wrong in
different ways. :)

#include <stdio.h>
#include <math.h>
void printld(long double* pld)
{
    int i;
    printf("*%p = ", pld);
    for (i = 0; i < sizeof(long double); ++i) {
        printf("%02x ", ((unsigned char*)pld)[i]);
    }
    printf("\n");
}

int main()
{
    long double number1 = 1.0;
    long double number2 = 1.0;

    printf ("%lf, %lf\n", number1, number2);

    printf ("Enter number1: ");
    scanf ("%lf", &number1);
    printf ("Enter number2: ");
    scanf ("%lf", &number2);

    printf ("%lf, %lf\n", number1, number2);
    printf ("%lf, %lf\n", number1, number1);

    printld(&number1);
    printld(&number2);
    return 0;
}

C:\tmp>gcc -o tmp.exe file.c

C:\tmp>tmp
0.000000, 0.000000
Enter number1: 3
Enter number2: 4
3.000000, 0.000000
3.000000, 0.000000
*0022FF30 = 00 00 00 00 00 00 08 40 ff 3f 00 00
*0022FF20 = 00 00 00 00 00 00 10 40 ff 3f 00 00

C:\tmp>gcc -std=c99 -o tmp.exe file.c

C:\tmp>tmp
1.000000, 1.000000
Enter number1: 3
Enter number2: 4
0.000000, 0.000000
0.000000, 0.000000
*0022ff30 = 00 00 00 00 00 00 08 40 ff 3f 00 00
*0022ff20 = 00 00 00 00 00 00 10 40 ff 3f 00 00

There was even a way of printing the same variable (number1) twice on a line
and it would output it twice.  That is why I had put in:

  printf ("%lf, %lf\n", number1, number1);

as a test, but it didn't show up in this test code.

C:\tmp>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.5.0/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.5.0/configure
--enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions
--with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry
--enable-libstdcxx-debug --enable-version-specific-runtime-libs
--disable-werror --build=mingw32 --prefix=/mingw

Thread model: win32
gcc version 4.5.0 (GCC)
--
A


             reply	other threads:[~2010-12-12 16:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-12 16:12 adrian.hawryluk at gmail dot com [this message]
2010-12-12 16:51 ` [Bug c/46908] " schwab@linux-m68k.org
2010-12-12 17:32 ` manu at gcc dot gnu.org
2010-12-12 22:53 ` adrian.hawryluk at gmail dot com
2010-12-12 22:55 ` adrian.hawryluk at gmail dot com
2010-12-12 23:09 ` adrian.hawryluk at gmail dot com
2010-12-13 18:28 ` [Bug target/46908] " jsm28 at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-46908-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).