Question : Size of integer in embedded

Hi, I have a simple/dumb question, which is a nice change from the murderers I've been asking lately.  

In embedded programming, I know the size of an integer can change from environment to environment.  However, I realize I don't know what determines the size of an integer, what does it depend on?  Is it the CPU make/model, or the compiler, or is it a combination?  (For example, I have 4 byte integers with IAR/at91sam9261, would I have 2 bytes with IAR and an 8 bit micro?)

Thanks for a brief education.

Answer : Size of integer in embedded

Why did you say "simple" and "dumb"?

I have the Answers for you - many answers. Here they are:

After reading the Answers, I'll give my opinion ...

But first, for your interpretation is an excerpt from The C Programming Language ANSI 2nd Edition by K&R:
"int will normally be the natural size for a particular machine. ... Each compiler is free to choose appropriate size for its own hardware, subject only o the restriction that shorts and ints are at least 16 bits, longs are at least 32 bits, and short is no longer than int, which is no longer than long."

My answer...
It's the compiler, not the OS, not the CPU, not the memory, not the board.

In any case, if you care about the size, then you should never use int. I rarely say never. This is one case. It's OK for some simple for-loop counters. You can define your own user_types.h file that does a typedef for uint32, uint16, uint8, sint32, sint16, and sint8; and if applicable, uint24, uint64, sint24 and sint64. Then as you move from one processor to another, just #if defined(PROCESSOR_NAME) to get the typedef correct for that platform. I wouldn't rely on 64-bit integer types though since there may not be an equivalent in your compiler.
Random Solutions  
programming4us programming4us