Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MSVC 6: How to printf() a 64-bit long?

2,632 views
Skip to first unread message

e.e.s...@cummins.com

unread,
Dec 10, 1998, 3:00:00 AM12/10/98
to
// A constant for max negative 64-bit long
LONG64 long64 = 0x800000000000000l;

// Questions: Is there a format specifier to use with printf for a 64-bit
long? // "%ld" does not work, it prints out a single zero. printf( "%ld",
long64 );

MSVC 6.0 makes the following 64-bit typedef's in <basetsd.h>.

// The following types are guaranteed to be unsigned and 64 bits wide.
typedef __int64 LONG64, *PLONG64;
typedef __int64 INT64, *PINT64;
typedef unsigned __int64 ULONG64, *PULONG64;
typedef unsigned __int64 DWORD64, *PDWORD64;
typedef unsigned __int64 UINT64, *PUINT64;

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Phil Howard

unread,
Dec 10, 1998, 3:00:00 AM12/10/98
to
On Thu, 10 Dec 1998 19:23:14 GMT e.e.s...@cummins.com wrote:

| // A constant for max negative 64-bit long
| LONG64 long64 = 0x800000000000000l;
|
| // Questions: Is there a format specifier to use with printf for a 64-bit
| long? // "%ld" does not work, it prints out a single zero. printf( "%ld",
| long64 );

glibc/gcc (it's a UNIX thang, but you can also get it for MS-Windows
whatever) supports the "long long" data type, and does formats for it
by simply putting "ll" instead of "l" in the format specification.

It may or may not work in Windows VC++ but give it a try anyway. If
that doesn't work, try other things like "L" or "LL". You might just
stumble onto it.

The next version of C supposedly will standardize these extensions.

--
-- *-----------------------------* Phil Howard KA9WGN * --
-- | Inturnet, Inc. | Director of Internet Services | --
-- | Business Internet Solutions | eng at intur.net | --
-- *-----------------------------* philh at intur.net * --

Tomas Restrepo

unread,
Dec 10, 1998, 3:00:00 AM12/10/98
to
<e.e.s...@cummins.com> wrote in message 74p72u$s19$1...@nnrp1.dejanews.com...

>// A constant for max negative 64-bit long
>LONG64 long64 = 0x800000000000000l;
>
>// Questions: Is there a format specifier to use with printf for a 64-bit
>long? // "%ld" does not work, it prints out a single zero. printf( "%ld",
>long64 );

Use the %I64 syntax. For example, to print it in hex use:

printf ("%#I64x", lon64);

Anyway, it's documented along with the other format specifiers.

Tomas Restrepo
win...@bigfoot.com
http://members.xoom.com/trestrep/


Dan Pop

unread,
Dec 10, 1998, 3:00:00 AM12/10/98
to
In <74p72u$s19$1...@nnrp1.dejanews.com> e.e.s...@cummins.com writes:

>// A constant for max negative 64-bit long
>LONG64 long64 = 0x800000000000000l;
>
>// Questions: Is there a format specifier to use with printf for a 64-bit
>long? // "%ld" does not work, it prints out a single zero. printf( "%ld",
>long64 );

Why did you expect it to work, since %ld expects a long int argument,
which is 32 bits in Windows?

The obvious place to look for the answer is the printf documentation that
comes with your compiler.

Since you cross-posted this to comp.lang.c (where it doesn't belong,
because LONG64 is not a C type), all I can say is that the current C9X
draft specifies %lld for a long long int, a type which is guaranteed to
be at least 64 bits. I've no idea what Microsoft has chosen for LONG64.

Dan
--
Dan Pop
CERN, IT Division
Email: Dan...@cern.ch
Mail: CERN - EP, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland

0 new messages