2

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.

Community
  • 1
  • 1
Sahil
  • 117
  • 12
  • 3
    **@peopleWhoHaveVotedToClose** There are certain questions to be addressed. It may not be the exact duplicate. – Suhail Gupta Oct 12 '12 at 16:07
  • you can check as follows: [http://stackoverflow.com/questions/12739693/size-of-int-variable/][1] [http://stackoverflow.com/questions/2331751/does-the-size-of-an-int-depend-on-the-compiler-and-or-processor][2] [1]: http://stackoverflow.com/questions/12739693/size-of-int-variable/ [2]: http://stackoverflow.com/questions/2331751/does-the-size-of-an-int-depend-on-the-compiler-and-or-processor – pradipta Oct 12 '12 at 16:07
  • @pradipta did a grt job..but it will be good...if u try to give the original answer instead of duplicate questions – Sahil Oct 12 '12 at 16:38

0 Answers0