I'm using gcc version 4.1.2 on a RedHat Enterprise Linux 5 machine.
For i386 or x86_64? There's a huge difference.
I'm trying to print out a 64-bit integer with the value 6000000000
using the g++ compiler,
g++ is a C++ compiler; if you need assistance with C++, check with
comp.lang.c++. I'm going to pretend you said gcc since the answer is
probably the same and that'd be (at least close to) on topic.
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.
Different UNIX(ish) systems do different things, which is permitted by
the relevant standards. ILP32LL64 is common, and so is I32LP64; ILP64
can be found as well. There's probably a few other odd combinations out
there, though AFAIK IL32LLP64 is Windows-only. If your code is written
correctly, though, it shouldn't matter.
Then why does "ld" not display the 64-bit value correctly?
The first possibility is that you are not using the correct types, since
you appear to be unclear on exactly what types have what sizes for your
particular platform. If you're using Linux/x86, for instance, "long
int" is a 32-bit type and thus %ld cannot print 64-bit values.
A second possibility is that your compiler (gcc) and library (glibc)
disagree about the size of a long int; one might think it's 32-bit and
the other thinks it's 64-bit. This _shouldn't_ happen, and it's
unlikely since it'd break a heck of a lot of other things that would
make your system practically unusable, but in theory it's possible.
Also, in Windows (MS Visual Studio 2008), should I use the format
string "Id" (eye-d) to display 64-bit integers?
Good question; MS doesn't implement C99 and doesn't have long long int,
so exactly what to do with their system is off-topic here.
S