long and long long

I am sure, in java, size of long is 64 bits and there is not any datatype of long long. So, In C /C++ also, I used to think long is 64 bit and long long is bigger than 64 bit [128 bit]. But, recently I got a doubt regarding this. So, I have written a C program and compiled it on many systems. Size of long long is always 64bits. But size of long was varying based on compiler flags. In solaris, if we give cc longsize.c, by default ILP32 bit data model used. In this case, size of long is 32 bits. But, if we give cc -xarch=v9 longsize.c, code will be compiled for 64-bit SPARC machines and LP64 data model is used. In ILP32 bit model, size of integer, long and pointer is 32 bits. In LP64 data model, size of long and pointer is 64 bits. So, independent of machines and datamodels, if we want 64 bit data type, we have to use long long.

Then I have read in some article that long long is introduced recently to support very big numbers. we use %ld in printf to print long and %lld for long long.

http://developers.sun.com/prodtech/cc/articles/ILP32toLP64Issues.html

Update: Recently, I have learnt that, in windows, size of long in both 32 bit and 64 bit builds is same and it is 32 bits. It follows LLP64 [long long and pointer are 64 bit] data model in 64 bit builds.

Advertisements

2 Comments

  1. jayaram said,

    October 3, 2006 at 10:29 pm

    doopy..nenu guda oracle ki veltanu emo ra..manchi offer chestaru anipistondi..elagaina kpc website hack chesi andulo oracle peru pettendukani try chesta 😉

    f1 choostunnava?

  2. tombarta said,

    August 6, 2008 at 6:02 am

    If you need a specific sized integer, you should be using the C99 and headers, which declare types such as int64_t, uint32_t, int8_t, etc. It also #defines printf-style specifiers, such as PRi64, which should be preferred over “%lld” for said typedefs.

    Visual C++ doesn’t provide C99 support, but the google project msinttypes provides those two headers.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: