Size of datatype dependent on OS or Hardware Architecture?
-
hi i would like to know if whether the size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
-
hi i would like to know if whether the size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
size of int is depend on Compiler. Compiler is depend on Operating System. Operating System is depend on Hardware Architecture.
Do not trust a computer... Always check what computer is doing regards, Divyang Mithaiwala Software Engineer
-
hi i would like to know if whether the size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
According to the C spec,
int
is a convenient size for that system.char
,short
andlong
are always the same size. Not so sure aboutfloat
anddouble
... As for structures, they can also vary, due tostructure padding
. That should give you enough google material / questions to ask your teacher. Iain.In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[^]
-
hi i would like to know if whether the size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
QuickDeveloper wrote:
size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler
The data-type size is primarily specified by the compiler. The size used by the compiler will be chosen to make implementation of the data-type easy. So, on a 16-bit processor, ints are likely to be 16-bit, while on a 32-bit compiler, they're likely to be 32-bit. When you get to 64-bit hardware, you have more choices. 32- or 64-bit ints are natively supported, but you'll probably find they choose 32-bit integers because a) that is in general big enough for most applications, and b) 32-bit ints are half the size of 64-bit ints - moving all ints to 64-bit would probably cause space and speed (because you have to read twice as much memory for ints) issues. You still, of course have access to 64-bit ints through __int64 and long long.
QuickDeveloper wrote:
Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?
I don't believe so. IIRC, the 64-bit Windows API uses 32-bit integer values and 64-bit pointer values, compared to 32-bit Windows, which uses 32-bit integers and 32-bit pointers. [bit later] I've just checked (by compiling with the x86->amd64 cross-compiling version of VC++ and looking at the generated assembler) and VC++ does indeed use 32-bit integers for x86 AND x64.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p