Re: Printing a 64-bit integer



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/ |
-----------------------------------------------------------------------------
.



Relevant Pages

  • Re: Excel-based Front End Reporting Tool
    ... the architectures handle this differently. ... > Microsoft Analysis Services based management information solution at my ... > There is no reason to be on any other platform other than an Microsoft ...
    (microsoft.public.sqlserver.olap)
  • Re: Apples poor positioning for the age *after* x86
    ... features, but they work with the new DirectX. ... They did it because it is far too hard to switch. ... They realized the only way to achieve platform independence was to develop a software platform for the lowest common denominator. ... on the off chance that you might need to switch CPU architectures? ...
    (comp.sys.mac.advocacy)
  • Re: Use of C99 int types
    ... > but there's no guarantee that it will on other architectures. ... To port on such platform we'd have to do a lot of rewriting - so much that ... and any platform that doesn't satisfy the above will require very serious ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: 2.6.23-rc1-mm2
    ... at least and doesn't break every platform out there that has an existing ... stub. ... than having to duplicate all of this crap in the architectures. ... then it isnt in our interest to investigate it since our ...
    (Linux-Kernel)