cifer
cifer

Reputation: 633

Why does FreeRTOS use short and long type, but not int type?

From Using the FreeRTOS Real Time Kernel - Standard Edition, p143, I noticed that:

int types are never used – only long and short

I would like to know why, but I find no answer in its official site and no result after google.

Update 08/31:

Maybe my question is not so clear, in short, I just wonder that why FreeRTOS defines BaseType_t as long instead of int(and other FreeRTOS defined types are never use int, too). From its Coding-Standard-and-Style-Guide page, it said that:

BaseType_t

This is defined to be the most efficient, natural, type for the architecture. For example, on a 32-bit architecture BaseType_t will be defined to be a 32-bit type. On a 16-bit architecture BaseType_t will be defined to be a 16-bit type. If BaseType_t is define to char then particular care must be taken to ensure signed chars are used for function return values that can be negative to indicate an error.

From the above description, I think int is more suitable than long, since int is always conform to the architecture's word size.

Upvotes: 2

Views: 2920

Answers (2)

Bill Lynch
Bill Lynch

Reputation: 81936

The FreeRTOS coding standard disagrees with your reference.

The actual requirement is that you use typedefs that have been defined by RTOS, or the integer typedefs found in stdint.h, such as uint32_t. Normally, the types found in stdint.h are acceptable, because the size of those integers do not vary on different architectures.

Upvotes: 3

uri2x
uri2x

Reputation: 3202

Not an official answer by any means, by I would suppose they wanted to make sure their types are clearly defined, and therefore decided on 3 int types: char (uint8_t), short (unit16_t) and long (uint32_t). This way any confusion as to what's the size of int is avoided.

Upvotes: 0

Related Questions