printf("%?", long long)?

This is a discussion on printf("%?", long long)? within the C Programming forums, part of the General Programming Boards category; Btw, how to print/converting an unsigned or signed long long into string?...

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    printf("%?", long long)?

    Btw, how to print/converting an unsigned or signed long long into string?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    It should be %lld or %llu according to C99, but on MSVC it may have to be %I64, if I remember correctly.
    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

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    %I64l or %I64d or %I64u
    %I64 is a prefix that says it's a 64-bit type. You still would need to specify the actual type, such as integer or long (and if it's unsigned integer, it's u).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Code:
       unsigned long long ull = 2;
       
       int i;
       
       for(i=1; i<63; i++)
       {
          ull *= 2;
       }
       
       //for comparison...
       printf("9223372036854776000\n");
    
       printf("&#37;llu\n", ull);
       printf("%lld\n", ull);
       printf("%I64%\n", ull);
    And...

    Code:
       Output:
          9223372036854776000
          0
          0
          %
    Note: I'm using GCC...
    Last edited by audinue; 06-19-2008 at 11:55 AM.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    Note: I'm using GCC...
    Are you using the MinGW port of GCC, by any chance?

    EDIT:
    Right. I switched over to Linux and compiled with gcc 4.2.3, ran the program and the output was:
    Code:
    9223372036854776000
    9223372036854775808
    -9223372036854775808
    Of course, I had to remove the last printf() because the format specifier was non-standard.
    Last edited by laserlight; 06-19-2008 at 12:08 PM.
    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

  6. #6
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Yes, in Windows...

  7. #7
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    In a quick test I received the following


    9223372036854776000
    9223372036854775808
    -9223372036854775808
    % <----------result of I64

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    &#37;I64 is not supported in GCC...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    Yes, thanks, figured that or just did not have the proper #include.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Argh, the failings of C.
    Take heed of all and any warnings. They're there for a reason.
    Especially beware implicit function calls. It's THE most evil feature of C that should never have existed in the first place.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    Basically, I believe that there is a bug or lack of correct support for &#37;lld and %llu in the MinGW port of GCC. The bug could lie in the 3.x series of GCC, but I suspect it lies in the MinGW port itself.

    EDIT:
    The bug could be with long long arithmetic itself, but I am not sure.
    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

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I'm pretty sure I've posted this before. Upshot: MS didn't believe in long long, hence the C runtime on Windows doesn't believe in long long, hence you can't print it except through the MS-specific I64 thing.
    Last edited by tabstop; 06-19-2008 at 01:17 PM. Reason: tense

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  2. Having Buffer Problems With Overlapped I/O --
    By Sargera in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 03:46 PM
  3. Problem in Converting Unsigned long to String
    By cprogrammer_18 in forum C Programming
    Replies: 8
    Last Post: 01-14-2006, 07:57 AM
  4. Merge and Heap..which is really faster
    By silicon in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2005, 04:06 PM
  5. Insertion Sort Problem
    By silicon in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2005, 12:30 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