What is the size of an integer?
-
It might sound strange but as far as i know integer is 2 bytes . But in my code i declared such a simple array int arr[2][3][3] = { { {2000, 4,1}, {7, 8,1}, {3, 9,1} }, { {71, 61,11}, {31, 41,11}, {51, 91,11} } }; Why the hell do it store a integer as 4 byte in VC++ it a simple console app. :doh: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
-
It might sound strange but as far as i know integer is 2 bytes . But in my code i declared such a simple array int arr[2][3][3] = { { {2000, 4,1}, {7, 8,1}, {3, 9,1} }, { {71, 61,11}, {31, 41,11}, {51, 91,11} } }; Why the hell do it store a integer as 4 byte in VC++ it a simple console app. :doh: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
-
It might sound strange but as far as i know integer is 2 bytes . But in my code i declared such a simple array int arr[2][3][3] = { { {2000, 4,1}, {7, 8,1}, {3, 9,1} }, { {71, 61,11}, {31, 41,11}, {51, 91,11} } }; Why the hell do it store a integer as 4 byte in VC++ it a simple console app. :doh: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
See this... http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vccelng4/html/elconTypeint.asp[^]
Jesus Loves You and Me :)
--Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord
-
It might sound strange but as far as i know integer is 2 bytes . But in my code i declared such a simple array int arr[2][3][3] = { { {2000, 4,1}, {7, 8,1}, {3, 9,1} }, { {71, 61,11}, {31, 41,11}, {51, 91,11} } }; Why the hell do it store a integer as 4 byte in VC++ it a simple console app. :doh: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
-
actually, it is not OS dependent, but implementation dependent. standard states that sizeof(int) >= sizeof(short), and short is at least 16 bits. so, for different compilers, sizeof(int) can be different even on the same OS.
-
actually, it is not OS dependent, but implementation dependent. standard states that sizeof(int) >= sizeof(short), and short is at least 16 bits. so, for different compilers, sizeof(int) can be different even on the same OS.
and they are also processor dependent but not too much though. -Prakash -Prakash
-
and they are also processor dependent but not too much though. -Prakash -Prakash
Processor dependent ????? :confused: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
-
Processor dependent ????? :confused: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
Well to understand this u need to know how softwares are dependent on hardware (processor) generally the integer size is the size of word size of the processor, for 80386 onwards the word size is 32 bit and hence the integer size in most of the OS on Intel machine is 32bit. Why the size of integer varies from compiler to compiler/OS 2 OS, because integer is the most used datatype and transfering a 32bit of data from the memory to processor is more efficient than other sized data. -Prakash -Prakash
-
Probably i would preffer to say implementation dependent then processor dependent . :cool: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
-
Processor dependent ????? :confused: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
vikas amin wrote:
Processor dependent ?????
In continuation with Mr. Prakash.. if you see := sizeof(long)==sizeof(int) in windows enviornment
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
Probably i would preffer to say implementation dependent then processor dependent . :cool: Vikas Amin Embin Technology Bombay vikas.amin@embin.com
vikas amin wrote:
Probably i would preffer to say implementation dependent then processor dependent .
yes but the implementation is dependent on the processor. :)
-Prakash
-
actually, it is not OS dependent, but implementation dependent. standard states that sizeof(int) >= sizeof(short), and short is at least 16 bits. so, for different compilers, sizeof(int) can be different even on the same OS.
Zdeslav Vojkovic wrote:
...sizeof(int) can be different even on the same OS.
Do you have a valid example of such? I've never seen an
int
that varied in size on the same machine.
"Take only what you need and leave the land as you found it." - Native American Proverb
-
Zdeslav Vojkovic wrote:
...sizeof(int) can be different even on the same OS.
Do you have a valid example of such? I've never seen an
int
that varied in size on the same machine.
"Take only what you need and leave the land as you found it." - Native American Proverb
This goes back a bit in time, but... In Microsoft C 6.0 (MS-DOS era), an
int
was 16 bits. Watcom C 9.0, on the same machine, made anint
to be 32 bits. The Microsoft target in this case was 16-bit real-mode MS-DOS while the Watcom target was 32-bit protected mode MS-DOS.
Software Zen:
delete this; // [Fold With Us!](http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx)[[^](http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx "New Window")]
-
This goes back a bit in time, but... In Microsoft C 6.0 (MS-DOS era), an
int
was 16 bits. Watcom C 9.0, on the same machine, made anint
to be 32 bits. The Microsoft target in this case was 16-bit real-mode MS-DOS while the Watcom target was 32-bit protected mode MS-DOS.
Software Zen:
delete this; // [Fold With Us!](http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx)[[^](http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx "New Window")]
But was it a true 32-bit
int
? That's like saying we have a 64-bitint
today, but only because Microsoft's compiler mashes two 32-bitint
s together, simulating a bigger one.
"Take only what you need and leave the land as you found it." - Native American Proverb
-
But was it a true 32-bit
int
? That's like saying we have a 64-bitint
today, but only because Microsoft's compiler mashes two 32-bitint
s together, simulating a bigger one.
"Take only what you need and leave the land as you found it." - Native American Proverb
Actually it was. The 80386 processors and their descendents included direct 32-bit arithmetic and pointer support. The Watcom compiler supported protected mode execution with a flat memory model for a variety of DOS extenders. A "DOS extender" basically provided an execution environment for a protected mode application in the MS-DOS environment.
DavidCrow wrote:
Microsoft's compiler mashes two 32-bit ints together
Hmm. Is that still the case? I was under the impression that
__int64
support since VS.NET 2002 was provided directly by native instructions.
Software Zen:
delete this; // [Fold With Us!](http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx)[[^](http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx "New Window")]
-
Actually it was. The 80386 processors and their descendents included direct 32-bit arithmetic and pointer support. The Watcom compiler supported protected mode execution with a flat memory model for a variety of DOS extenders. A "DOS extender" basically provided an execution environment for a protected mode application in the MS-DOS environment.
DavidCrow wrote:
Microsoft's compiler mashes two 32-bit ints together
Hmm. Is that still the case? I was under the impression that
__int64
support since VS.NET 2002 was provided directly by native instructions.
Software Zen:
delete this; // [Fold With Us!](http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx)[[^](http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx "New Window")]
Gary R. Wheeler wrote:
Is that still the case?
I'm not sure since I only use VC++ v6.
Gary R. Wheeler wrote:
I was under the impression that __int64 support since VS.NET 2002 was provided directly by native instructions.
Even on processors that do not a have 64-bit bus?
"Take only what you need and leave the land as you found it." - Native American Proverb
-
vikas amin wrote:
Probably i would preffer to say implementation dependent then processor dependent .
yes but the implementation is dependent on the processor. :)
-Prakash
The most important thing to do is to always use the "sizeof" operation in any code you're referring to. Never, ever hardcode the size into your code. When reading/writing to a file - there are exceptions -- in general, avoid using "int" as a type when it comes to storage of data structures. Instead, define types such as DWORD, WORD, BYTE, etc. This will save you a lot of trouble down the road. Read more of what I have to say at http://directx9.blogspot.com/
-
The most important thing to do is to always use the "sizeof" operation in any code you're referring to. Never, ever hardcode the size into your code. When reading/writing to a file - there are exceptions -- in general, avoid using "int" as a type when it comes to storage of data structures. Instead, define types such as DWORD, WORD, BYTE, etc. This will save you a lot of trouble down the road. Read more of what I have to say at http://directx9.blogspot.com/
segment_fault wrote:
The most important thing to do is to always use the "sizeof" operation in any code you're referring to. Never, ever hardcode the size into your code. When reading/writing to a file - there are exceptions -- in general, avoid using "int" as a type when it comes to storage of data structures. Instead, define types such as DWORD, WORD, BYTE, etc. This will save you a lot of trouble down the road.
yes i know that.
-Prakash