![]() |
|
#1
|
|||
|
|||
Data types and Hardware dependenciesHi,
How do one determine the size of integer variable. Although there is a thumb rule that 32 bit processor allocates integer variable as 4 bytes (Similarly 16 bit processor, size of int is 2 bytes). But how exactly is the calculation arrived at in terms of the processor and the data type? Then why is it benchmarked only on integer variable like 4 bytes and referenced for other data types from integer. Thanks in advance, --Karthikeyan |
|
#2
|
|||
|
|||
|
Quote:
There are four integer data types (eight if you count signed and unsigned as separate types): char short int int long int According to the C standard: Quote:
The standard also requires the following: sizeof(char) is less than or equal to sizeof(short int) sizeof(short int) is less than or equal to sizeof(int) sizeof(int) is less than or equal to sizeof(long int) As has been mentioned, "old" C compilers (like Turbo C for DOS) typically had sizeof(int) equal to 2. There are people still running Turbo C 2.0 on Windows XP. For my AthlonXP processor on Windows XP, I find that: sizeof(char) = 1 sizeof(short) = 2 sizeof(int) = 4 sizeof(long) = 4 For an Athlon64 processor with 64-bit Linux you might expect that ints would be eight bytes, but I find that. sizeof(char) = 1 sizeof(short) = 4 sizeof(int) = 4 sizeof(long) = 8 Note that compilers can decide which size to use for an int, so merely knowing the hardware doesn't tell you what the size of an int is. The bottom line is that as a programmer, you should never, ever make an assumption as to the size of any particular object (except in cases where you have to). That is, keep system dependencies and implementation dependencies out of your programs as much as possible (and be sure to document any dependencies so that if you or anyone else compiles the program on a different system the danger points will be known). Of course you can find out what the sizes are on your system by spmething like this: CPP / C++ / C Code:
Regards, Dave |
|
#3
|
|||
|
|||
|
Quote:
Thanks for your reply,Dave. Your reply was really eye opener. Knowledge is power !!!! Karthikeyan.India |
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The