Assume to have
function f(int8_t a, int8_t b) // a b only need 8 bits
Another option is:
function f(int32_t a, int32_t b) // a b only need 8 bits
It runs in 32bits MCU, like ARM Cortex_M
. Which one is better option with respect to required code size, data size and executing efficiency?
If in 8 bits MCU such as 8051, the int8_t
should be better, right?
C provides you in
stdint.h
some more types for which you can assume that the question is answered at the compiler implementation level. Extract from C99 Draft :7.20.1.3 Fastest minimum-width integer types
1 Each of the following types designates an integer type that is usually fastest255) to operate with among all integer types that have at least the specified width.
2 The typedef name int_fastN_t designates the fastest signed integer type with a width of at least N. The typedef name uint_fastN_t designates the fastest unsigned integer type with a width of at least N.
3 The following types are required: int_fast8_t int_fast16_t int_fast32_t int_fast64_t uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t
So provided they are defined in your architecture just use
int_fast8_t
(oruint_fast8_t
)