Declaring the
int
's inside the loop does not affect performance. The allocation for that object is done on the stack when you enter the function. Also an int has no constructor, which is the crucial part. Declaring an int does not generate any code.
Objects having non-trivial constructors is another issue, and should be given special concern when dealing with loops that requires performance.
Also, watch out for overflow in statements like this
(int)(b[j] + b[j+3]);
If you have nothing better to do, you could also unroll the loop.
Edit:
There is something else bothering me with your code. Why do you use a
void*
as argument to your function if you only accept a
short*
implementing it? Would it not be better to have a
short*
as argument and let the caller, who probably knows your void pointers content a lot better than the add() function, do the conversion?