Hello David,

2009/10/25 David Cleaver <wrai...@morpheus.net>:
> Hello,
>
> I'm having problems printing out values that are larger than 32 bits.  My 
> usual
> printf using %llu only outputs the lower 32 bits of my 64-bit numbers.
>
> Here's an example program that produces incorrect output.
>
> #include <stdio.h>
>
> typedef unsigned long long u64_t;
>
> int main(int argc, char* argv[])
> {
>   u64_t y=6981463658333LL;
>   printf("y=%llu\n", y);
>   printf("y=%PRIu64\n", y);
>   printf("y=%qd\n", y);
>   printf("y=%x\n", y);
>   return 0;
> }
>
> Here is the output I get.
> y=2141802333
> y=PRIu64
> y=qd
> y=7fa94f5d
>
> Can anyone see what I'm doing wrong?  What is the proper way to output 64-bit
> numbers?  I'm using mingw-w64-bin_i686-mingw_20091025.zip for my development
> environment and I've called the compiler like:
> x86_64-w64-mingw32-gcc.exe -o test.exe test.c
>
> Thanks for any help.
>
> -David C.

The reason for this is the msvcrt you are using. The %ll width
specifier is support by MS until msvcrt based on msvcr80.dll. The
common width specifier, which works also for older msvcrt.dll
versions, is %I64.
If you want to use POSIX like printf formatters, like "%ll" or "%Lg",
then you should use our POSIX emulation version for it. You need just
to define by command line, or before including the first header file,
the macro __USE_MINGW_ANSI_STDIO with value one.

For the example you gave it would look like that

#define __USE_MINGW_ANSI_STDIO 1
#include <stdio.h>

typedef unsigned long long u64_t;

int main(int argc, char* argv[])
{
  u64_t y=6981463658333LL;
  printf("y=%llu\n", y);
  printf("y=%PRIu64\n", y);
  printf("y=%qd\n", y);
  printf("y=%x\n", y);
  return 0;
}

I hope I could help you by this.

Cheers,
Kai

-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to