long int vs. int

General discussion about C/C++

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

long int vs. int

Postby DannyBoy » Wed Dec 31, 2008 2:01 pm

I'm struggling to find a definitive answer for this: are long int and int virtually synonymous now? Some sites give the same ranges and sizes (in bytes) for the two, suggesting that they are effectively the same. Is it platform and compiler dependent?
User avatar
DannyBoy
 
Posts: 1160
Joined: Fri Feb 13, 2004 12:56 pm
Location: In the Billiard Room with the Lead Pipe

Postby MXP » Fri Jan 02, 2009 9:26 pm

I believe they are technically platform and compiler dependent.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Darryl » Sat Jan 03, 2009 6:25 am

are long int and int virtually synonymous now?


Back in the days when we programmed 32 bit system :-) I would have agreed that they mostly were the same on the most popular platforms/compilers, but lately with 64 bit coming of age I am seeing that int is often 32 bit and long is 64.

By the standard though, the only guarantee made is that long is at least as big as int.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Alvaro » Sat Jan 03, 2009 9:35 am

Darryl wrote:By the standard though, the only guarantee made is that long is at least as big as int.

The standard also guarantees that long can represent integers in the range [-2147483647,2147483647]. In practice this means that they are at least 32-bit integers. Note that ints can be 16-bit integers.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby MXP » Sat Jan 03, 2009 10:09 pm

Microsoft compilers leave long as a 32-bit type even in 64-bit environments.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest