Click to See Complete Forum and Search --> : What determines the size of int?


Talikag
July 2nd, 2008, 08:57 PM
The size of int changes. Sometimes it takes 16 bits in the memory (2 bytes), while in other cases it might take 32 bites (4 bytes).

I claim the compiler determines the size, but some people told me it's up to the architecture (i.e., the processor).

Am I right here?

TheCPUWizard
July 2nd, 2008, 09:16 PM
Technically yes the compiler determines what (machine level) instructions will be used. However it is the physical architecture that determines the optimal size for an int based on how much memory can be accessed in a single instruction.

Note that this is not walywas a multiple of 8 bits either :eek: I have worked on machines with 12 bit ints (DEC PDP), 18 bit ints (DG Nova), and 36 bit ints (IBM).

Talikag
July 2nd, 2008, 09:25 PM
Thanks for you quick post.
Just a question though, if the size of a register is 32 bits, the maximum size for an int-based intruction is 32x2 (64 bits)?

18 bits ints? really? kinda wierd. thought sizes in multiples of 4 & 8 are more accessible for the processor.

TheCPUWizard
July 2nd, 2008, 09:54 PM
Thanks for you quick post.
Just a question though, if the size of a register is 32 bits, the maximum size for an int-based intruction is 32x2 (64 bits)?

18 bits ints? really? kinda wierd. thought sizes in multiples of 4 & 8 are more accessible for the processor.

It was only with the advent of the microprocessor that multiples of 4 became prevelant. The DEC PDP-8 used a 12 bit word, the Data General Nova an 18 bit word, and most IBM "big iron" a 36 bit word.

Even with the Intel microprocessors, the:

4004 could only address 4 bits at a time,
8008 and 8080 only 8 bits at a time
8088 had a 16 bit internal architecture but still used an 8 bit data bus.
8086 was the first to be able to address 16 bits in a single cycle.
etc....

Also consider that the processor speeds for the above mentioned machines ran from 500Khz to 4Mhz.....

Talikag
July 2nd, 2008, 10:33 PM
Ok, thanks for your posts.
Tried to rate your post but apparently I have to spread some reputations around before...