JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
[ 1 2 ]    NEXT >
int's and long's | Reply
I'm a Java programmer, so I'm curious...

What is the difference between a C++ int and a C++ long? They both use the same number of bits, and they have the same range of numbers.

And, by the way, this is a great and informative article. Thanks, misof!
Re: int's and long's (response to post by thecalcgenius) | Reply
They're not always the same. As misof said in the article, int is always guaranteed to have at least 16 bits, and long is guaranteed to have at least 32 bits. With the setup that TC uses (x86 hardware and g++) they happen to have the same number of bits and therefore the same range, but it's not always the case.
Re: int's and long's (response to post by aussie) | Reply
What are the determining factors,such that, within a certain architeture a type will have a certain size? In your case(x86 hardware and g++), why is long and int the same?

Is it not the case that some types are derivable from fundamental ones? Therefore it must follow that "long" can be standardised to be 32 bits and "int" to be 16 bits regardlesss of hardware because the compiler can take care of the implementation at higher level if the hardware cannot rep a type.
Re: int's and long's (response to post by thecalcgenius) | Reply
I am also a Java programmer. I would like to know whether the information in the article can be applied to Java programs?
Re: int's and long's (response to post by dimkadimon) | Reply
It can. Just ignore the parts about the data type "long long" and all the unsigned data types.
Re: int's and long's (response to post by mafoko) | Reply
int is supposed to be the word size of the machine, that is the size such that operations are optimized for it. x86 machines are optimized for 32 bits, so we can have ints being the same as longs.

Not all machines are gauranteed to have bytes that are even 8 bits. Further some machines are optimized for different sized words. Since performance is important to c++ it makes more sense to say "int is the best variable to use if you need at least 16 bits of data or if you know you need more but are making platform specific code; long is for when you need more data."
Re: int's and long's (response to post by thecalcgenius) | Reply
Really, it's half-way about naming stuff.


g++ on x86 Java C# VB .NET
signed char byte sbyte ----
unsigned char ---- byte Byte
signed short short short Short
unsigned short char ushort,char ----
signed int/long int int Integer
unsigned int/long ---- uint ----
signed long long long long Long
unsigned long long ---- ulong ----
float float float Single
double double double Double
long double ---- ---- ----
---- ---- decimal Decimal

And I think some of the issues with extended doubles and g++ optimizations don't apply to Java (don't know about .NET). The big difference between C++ and the others is that C++ isn't the same on every compiler and platform (if you learn what stuff means in Java, you don't get confused when you change compilers).

Edit: changed "extended double" to "long double", because that's actually what g++ calls it. Also added VB.NET
Re: int's and long's (response to post by Ryan) | Reply
You lifted the fog of confusion! Well said.Thanks for helping me out in other posts too ryan.I thought I will be repeating myself too much with a phlethora of gratitutes. Appreciate. :)
Re: int's and long's (response to post by Ryan) | Reply
Ah. I get it. Thanks for the clarification.
Re: int's and long's (response to post by Kawigi) | Reply
Wow, I didn't know that g++ had that many "primitive" (for lack of a better word) data types.
Re: int's and long's (response to post by Kawigi) | Reply
I think you mean long double, not extended double.
Re: int's and long's (response to post by Kawigi) | Reply
I've seen "long double", but not "extended double". Is that terminology, or the actual type name?
Re: int's and long's (response to post by aboyner) | Reply
Yep, long double is what g++ calls it. Fixed that. Also added the VB.NET numeric types (I don't think characters can be used as numbers in VB, but I'm probably wrong, because I didn't try it).
Re: int's and long's (response to post by Kawigi) | Reply
VB.NET also has SByte, UShort, UInteger and ULong. Also, there are very few things that can be done in either C# or VB.NET that can't be done in the other, Char's can be used as numbers just as easily in VB as in C#, although there isn't usually any reason to since there's already an unsigned short integer type.
Re: int's and long's (response to post by Ryan) | Reply
I think it was more or less recently changed the standard so as to let int and long be fixed at 32-bit size in new versions. I couldn't find any references for this, i just heard it in a C++ vs Pascal conversation during the informatics olympiad of my country.
[ 1 2 ]    NEXT >

RSS