CONFUSION

1 view
Skip to first unread message

shona

unread,
Aug 12, 2010, 12:40:22 PM8/12/10
to Knowledge Test
how the size of an integer is decided? - is it based on processor or
compiler or OS?

TheSuyog

unread,
Aug 12, 2010, 1:15:18 PM8/12/10
to Knowledge Test
There's no such rule but by convention, the size of int is based on
processor, size of its registers, to be precise. Like on 32-bit
processors size of int is 32 bits (4 bytes), on 16-bit processors it
is 2 bytes. Size of int is kept at the native size of the processor.
But it actually depends on the compiler, the way it implements the int
datatype. OS's got nothing to do with this.

shona

unread,
Aug 12, 2010, 1:22:17 PM8/12/10
to Knowledge Test
definitely os bcoz.c compiler occupies 2 bytes in windows
where as the same c compiler occupies 4 bytes in linux.

shona

unread,
Aug 12, 2010, 1:24:55 PM8/12/10
to Knowledge Test
compiler too but not processor not sure..

if compiler is 16 bit compiler then int is of 2 bytes (turbo c)
if compiler is 32 bit then int is of 4 bytes in VC++

but for 32 bit compiler processor should be compatible i.e. of 32
bytes
so processor also decides it
again of OS
if os is 16 bit how you r going to run a 32 bit compiler on it

so a confusing question

TheSuyog

unread,
Aug 12, 2010, 1:46:29 PM8/12/10
to Knowledge Test
Its not that a 16-bit compiler can not produce 32-bit assembly code or
a 32-bit compiler can not produce 64-bit code or vice versa. It all
depends on how the compiler translates the source program into the
machine program.
It does not depend on the processor at all, its just a convention to
have the size of int according to the processor...because the
registers of a 32-bit processor can store a 32 bits long integer
number then why waste space?
And OS's has definitely got nothing to do with this because for one
thing Windows supports 4 byte long integer and not 2 byte long and for
second thing ever tried checking the size of int in Unix running on a
16-bit system?
Reply all
Reply to author
Forward
0 new messages