Re: Printing a 64-bit integer
- From: phil-news-nospam@xxxxxxxx
- Date: 7 Sep 2009 12:50:35 GMT
On Mon, 7 Sep 2009 03:20:23 +0000 (UTC) Alan Curry <pacman@xxxxxxxxxxxxx> wrote:
| In article <508b7147-0a3c-4862-885c-d897754e44c8@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
| lancer6238@xxxxxxxxx <lancer6238@xxxxxxxxx> wrote:
|>Hi all,
|>
|>I'm using gcc version 4.1.2 on a RedHat Enterprise Linux 5 machine.
|>I'm trying to print out a 64-bit integer with the value 6000000000
|>using the g++ compiler, and realized that using the format string
|>"ld" (ell-d) did not work, but "lld" (ell-ell-d) works. My question is
|>that I thought Unix uses the LP64 data model, so long integers should
|>be 64-bit. Then why does "ld" not display the 64-bit value correctly?
|
| "Unix uses the LP64 data model" is something you have taken out of context
| and over-generalized. It doesn't apply to 32-bit architectures. It's useful
| for contrasting the behavior of 64-bit unix systems (for example Linux/amd64
| which is LP64) with the behavior of other systems (for example 64-bit
| Microsoft stuff?)
It could still be done on 32-bit architectures. It would generate some
nasty code to do that, especially with pointers (check that the upper half
is 0 before loading the lower half).
| Or stop letting your current platform influence your type selection and use a
| type that is guaranteed to be suitable on every platform - if bare "long long"
| isn't it, then something from <inttypes.h> probably is.
Agreed. If I need 64 bit, I use int64_t or uint64_t, to be sure I get what
what I expect. I could use long long or unsigned long long. But on some
platform that might actually end up being 128 bits, some day.
--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
.
- References:
- Printing a 64-bit integer
- From: lancer6238@xxxxxxxxx
- Re: Printing a 64-bit integer
- From: Alan Curry
- Printing a 64-bit integer
- Prev by Date: Re: Printing a 64-bit integer
- Next by Date: Re: Statement on Schildt submitted to wikipedia today
- Previous by thread: Re: Printing a 64-bit integer
- Next by thread: Re: Printing a 64-bit integer
- Index(es):
Relevant Pages
|