public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/46908] New: printf not handling printing of double correctly in certain cases
@ 2010-12-12 16:12 adrian.hawryluk at gmail dot com
  2010-12-12 16:51 ` [Bug c/46908] " schwab@linux-m68k.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: adrian.hawryluk at gmail dot com @ 2010-12-12 16:12 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/46908] printf not handling printing of double correctly in certain cases
  2010-12-12 16:12 [Bug c/46908] New: printf not handling printing of double correctly in certain cases adrian.hawryluk at gmail dot com
@ 2010-12-12 16:51 ` schwab@linux-m68k.org
  2010-12-12 17:32 ` manu at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: schwab@linux-m68k.org @ 2010-12-12 16:51 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> 2010-12-12 16:51:28 UTC ---
l has no effect on %f.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/46908] printf not handling printing of double correctly in certain cases
  2010-12-12 16:12 [Bug c/46908] New: printf not handling printing of double correctly in certain cases adrian.hawryluk at gmail dot com
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu.org @ 2010-12-12 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2010-12-12 17:32:26 UTC ---
Use -Wall:

test.c:18: warning: format ‘%f’ expects type ‘double’, but argument 2 has type
‘long double’

which means that %f is not for long double, you should use %Lf and it will
work.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/46908] printf not handling printing of double correctly in certain cases
  2010-12-12 16:12 [Bug c/46908] New: printf not handling printing of double correctly in certain cases adrian.hawryluk at gmail dot com
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: adrian.hawryluk at gmail dot com @ 2010-12-12 22:53 UTC (permalink / raw)
  To: gcc-bugs

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

Adrian Hawryluk <adrian.hawryluk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #3 from Adrian Hawryluk <adrian.hawryluk at gmail dot com> 2010-12-12 22:53:43 UTC ---
Sorry, changed to %Lf with same results.   

#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;
}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/46908] printf not handling printing of double correctly in certain cases
  2010-12-12 16:12 [Bug c/46908] New: printf not handling printing of double correctly in certain cases adrian.hawryluk at gmail dot com
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: adrian.hawryluk at gmail dot com @ 2010-12-12 22:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Adrian Hawryluk <adrian.hawryluk at gmail dot com> 2010-12-12 22:55:47 UTC ---
But found that "L" is not a known conversion type character.  When is "L"
supposed to be implemented?

C:\tmp>gcc -Wall -o tmp.exe file.c
file.c: In function 'main':
file.c:18:5: warning: unknown conversion type character 'L' in format
file.c:18:5: warning: unknown conversion type character 'L' in format
file.c:18:5: warning: too many arguments for format
file.c:21:5: warning: unknown conversion type character 'L' in format
file.c:21:5: warning: too many arguments for format
file.c:23:5: warning: unknown conversion type character 'L' in format
file.c:23:5: warning: too many arguments for format
file.c:25:5: warning: unknown conversion type character 'L' in format
file.c:25:5: warning: unknown conversion type character 'L' in format
file.c:25:5: warning: too many arguments for format
file.c:26:5: warning: unknown conversion type character 'L' in format
file.c:26:5: warning: unknown conversion type character 'L' in format
file.c:26:5: warning: too many arguments for format


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/46908] printf not handling printing of double correctly in certain cases
  2010-12-12 16:12 [Bug c/46908] New: printf not handling printing of double correctly in certain cases adrian.hawryluk at gmail dot com
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: adrian.hawryluk at gmail dot com @ 2010-12-12 23:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Adrian Hawryluk <adrian.hawryluk at gmail dot com> 2010-12-12 23:08:58 UTC ---
Used flag -std=c99 and this reduced the number of warnings.  They were limited
to the scanf format string.

C:\tmp>gcc -Wall -std=c99 -o tmp.exe file.c
file.c: In function 'main':
file.c:21:5: warning: unknown conversion type character 'L' in format
file.c:21:5: warning: too many arguments for format
file.c:23:5: warning: unknown conversion type character 'L' in format
file.c:23:5: warning: too many arguments for format


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/46908] printf not handling printing of double correctly in certain cases
  2010-12-12 16:12 [Bug c/46908] New: printf not handling printing of double correctly in certain cases adrian.hawryluk at gmail dot com
                   ` (4 preceding siblings ...)
  2010-12-12 23:09 ` adrian.hawryluk at gmail dot com
@ 2010-12-13 18:28 ` jsm28 at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2010-12-13 18:28 UTC (permalink / raw)
  To: gcc-bugs

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

Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|c                           |target
         Resolution|                            |INVALID

--- Comment #6 from Joseph S. Myers <jsm28 at gcc dot gnu.org> 2010-12-13 18:28:22 UTC ---
GCC knows about the limitations of the Windows (msvcrt) printf and scanf
functions, which do not support all standard C99 formats, and the warnings are
telling you that they are not supported by those libraries.  The MinGW
libraries (wrapping msvcrt) are a separate project from GCC and there is no GCC
bug here.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-12-13 18:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-12 16:12 [Bug c/46908] New: printf not handling printing of double correctly in certain cases adrian.hawryluk at gmail dot com
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

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).