When passing variables by reference, should you keep the same variable name in the function?
In the general case no. Or at least there is no reason why they should.
In fact I would suggest you might want to approach the issue from the other way, and say
"should the calling function use variable names that are the same as
the parameter name in functions it is calling?"
In this case the answer is maybe
For instance, if an api to send a message takes a parameter named msg, you might want your calling function to use the same variable name
However, the important rule is that the variable name inside the function you are calling should make sense in the context of that function, and the variable name in the calling function should make sense in that context.
For instance:
int SendMsg( Msg& msgToSend)
{
// Serialise and transmit message
return OK;
}
void GenerateAndSendShutdown (void)
{
//You could call this msgToSend, but it wouldnt make the code any clearer
Msg shutdownCmd = "Shutdown";
SendMsg (shutdownCmd);
}
In your particular case, I would say it would make sense if they were the same.