Like Tree4Likes
  • 1 Post By laserlight
  • 2 Post By stahta01
  • 1 Post By Ocifer

Unexpected output in Code::Blocks for specifier %Lf

This is a discussion on Unexpected output in Code::Blocks for specifier %Lf within the C Programming forums, part of the General Programming Boards category; Here's the code that works in Xcode C on OSX but not Windows XP using Code::Blocks version 10.05 May 27, ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    132

    Unexpected output in Code::Blocks for specifier %Lf

    Here's the code that works in Xcode C on OSX but not Windows XP using Code::Blocks version 10.05 May 27, 2010 build:
    Extra info, C code using MinGW/GCC

    Code:
    long double a = 3.4;
    printf("a is %Lf \n",a);


    Output on OSX is "a is 3.4"
    On Win XP it is "a is -42307582002573505000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 000000000000000000000000.000000"

    Why please?

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    83
    Quote Originally Posted by FloridaJo View Post
    Here's the code that works in Xcode C on OSX but not Windows XP using Code::Blocks version 10.05 May 27, 2010 build:
    Extra info, C code using MinGW/GCC

    Code:
    long double a = 3.4;
    printf("a is %Lf \n",a);


    Output on OSX is "a is 3.4"
    On Win XP it is "a is -42307582002573505000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 000000000000000000000000.000000"

    Why please?
    C data types - Wikipedia, the free encyclopedia --- see the table
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    132
    I don't see what you are pointing out.
    Shouldn't a long double be able to handle 3.4 or 1.0 for that matter?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    It could be a compiler or standard library bug. You could try:
    Code:
    long double a = 3.4L;
    and if it works, then perhaps the bug is with conversion from double to long double, otherwise the bug might be with printf. Of course, I am assuming a bare bones test program, otherwise the bug might be with the code that you did not show.
    FloridaJo likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    132
    Yes, bare bones test code.
    That is the only code.
    Using 3.4L did not change anything.
    It's a 10 year old computer, the Code::Blocks is newly loaded on it,
    but I'm not sure if the Compiler came with it or it's pulling it from
    within the computer and there's a bug in that.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    2,771
    From reading several sites Google turned up; MinGW GCC supports a long double that is NOT a perfect match to what Microsoft C run-time does. Since MinGW uses Microsoft C run-time to do printf it fails to work right.

    NOTE: If you compiled with warning on you would see warnings.

    Tim S.
    Ocifer and FloridaJo like this.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  7. #7
    Registered User
    Join Date
    Apr 2010
    Posts
    83
    Quote Originally Posted by FloridaJo View Post
    Yes, bare bones test code.
    That is the only code.
    Using 3.4L did not change anything.
    It's a 10 year old computer, the Code::Blocks is newly loaded on it,
    but I'm not sure if the Compiler came with it or it's pulling it from
    within the computer and there's a bug in that.
    Sorry about my non-specific initial reply. I thought it would just be a matter of the using the right type specifiers. However, I came across this (after having the same problems you did on W7 and Code::Blocks, MinGW).

    Printing "long double" type via printf() on MinGW g++ 3.2.3 - C / C++

    It hints that MinGW might be broken in this respect, which is news to me. Bears some more reading anyway.

    Don't think it's your fault. On linux, using %Lf worked fine, with or without appending "L" to the literal assignment. Had the exact same problems with CB and MinGW

    EDIT: stahta01 beat me to the punch!
    FloridaJo likes this.
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    132
    Yes, it appears it is a MinGW problem or the library MinGW uses. Not sure which.
    But either way, thanks everyone for saving some more hairs on my head.
    I just use that computer in my shop to play around with, the iMac is a better station.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unexpected output
    By juice in forum C Programming
    Replies: 24
    Last Post: 11-18-2011, 11:18 PM
  2. Unexpected output
    By GolDRoger in forum C Programming
    Replies: 9
    Last Post: 11-18-2011, 02:49 PM
  3. Output from Code::Blocks Compiler
    By zilefac in forum C++ Programming
    Replies: 4
    Last Post: 08-21-2010, 02:19 PM
  4. unexpected output
    By crash88 in forum C Programming
    Replies: 2
    Last Post: 05-16-2006, 10:03 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21