Consider following piece of C code -
char sum_char(char a,char b)
{
char c = a+b;
return c;
}
It involves -
- Convert second parameter to sign extension.
- Push signed extension parameter on stack as b.
- Convert first parameter to sign extension.
- Push signed extension parameter on stack as a.
- Add a & b, result cast to char and store it in c.
- C is again sign extended.
- Sign extended c is copied to return value register and function return to caller.
- To store result caller function again convert int to char.
My questions are -
- Who does this ?
- What is necessity of doing so many conversions ?
- Will it reduce/increase the performance of machine/compiler ?
- If it is reducing performance what should we do in order to increase it ?