I was wondering if there is some cost saving, either in time or space by passing and/or returning smaller arguments? char vs int.
I have heard the compiler will optimize the code based on the type of the processor 8,16,32 bits. I think it will pass using a register, so that would be the max value of the register. Personally, I think if the count ever needs to grow, the function does not need to be changed. Still others will argue that "Since we are only counting to say 254, we only need an unsigned char. We are saving 24 bits of space, etc". Also, I think that there is more trouble with casting and it's better to use the largest register value type. I think it is better to pass using the larger arguments. Am I right or wrong?
/* Using smaller parameter */
unsigned char max_count = 10;
count(max_count)
void count(unsigned char max_count)
{
}
/* Using larger parameter */
unsigned long max_count = 10;
count(max_count)
void count(unsigned long max_count)
{
}
/* Examples that I come across (MISRA goes nuts with this statement) */
unsigned char do_something(unsigned char a)
{
...
return ((b | 0x12) << 2);
}