Possible Duplicate:
Does the size of an int depend on the compiler and/or processor?
I am using 64 bit
OS (windows 7) and using Dev C++
compiler (32 bit) . I also use Microsoft Visual C++
(32 bit) .
I am confused over the size of primitives. (int,char,short etc) Please address my few questions :
• On what does the size of these data types depend ? I have heard that the sizes vary with the kind of processor , operating system , compiler. Is that so ? If yes , please explain how do they vary.
• If I am using 64 bit OS and 32 bit compiler , the binary that will be produced will be compatible for both 32 OS and 64 OS ? Please address this issue properly and give a clear and a precise answer.
• What are the factors influencing the binary produced on a particular platform ?
• Suppose a binary is produced with a 32 bit compiler on 32 bit linux , will it be any different on 32 bit windows ?
• How is the range of a data type like int
defined ? On what factors does it depend ? Earlier I read that it is 32767
but while using Microsoft visual C++ it is greater than 32767
. Is the range totally dependent on compiler or it also depends upon the Operating system or what type of processor it is ?
• Let there be a program :
#include<iostream.h>
using namespace std;
int main() {
int x;
cout<<sizeof(x);
}
While using Microsoft Visual C++ 2010 (32 bit) on 32 bit windows , it prints 4
as the answer. Will this result vary if I run it on 64 bit platform ? In any case give a proper reason with the answer.