Question: I was discussing with a friend the following function prototype:

```
void str_buf_append(const char&);

```

The purpose is simply to add a character to a string buffer along with some other tasks irrelevant to the current question, which is: Given that we're not modifying the input character, is it better to pass by reference here or by value?

My friend's argument was that if you pass by reference for a char, you're putting onto the stack something with the size of an int whereas if you pass by value, you just put something on there that's only a byte in size.

In my opinion, though, that's not the whole picture: When you pass by value, I think you're actually doing the following:

1. Create a copy of the character at some location in memory distinct from that of the original character.
2. When the function is called, push onto the stack a reference to the copied character, thus not saving anything because under the hood, you're still using a pointer--just a pointer to a different memory location.

So my conclusion/opinion is that it is indeed more efficient to pass by reference than by value in this case.

Who is right?

Answer: 
The fact is that you can't predict what it will look like after optimizations take place; the only thing that stays "fixed" is the semantics of the code, not how it is actually executed.
Your both wrong.

A reference requires a pointer to the original object. Not an int. probably 64 bits. 

A char is pushed onto the stack, not copied elsewhere in memory and with standard packing this is probably like an int also 64 bits.

The pointer in question has to be deference later to get the value of the reference pulling in an entire cache line of 64 bytes on most hardware, if its not already in cache from the call. You would need to pull in the same cache line to push it on the stack, so very little difference there. BUT if the char was stored in a register, then that could have been pushed on the stack without a cache line being read in.

And If your optimizing for speed, it could probably stay in the same register if it were not a reference. The smart compiler guys might see that your doing something stupid like passing a pod type by const reference and keep it in a register to make you look good, but you shouldn't always rely on the compiler guys making you look good.

Unless your worried that someone might accidentally change the value of the char inside this function then why are you passing it as a const ref?

Every compiler / platform is different, and sometimes the ref may cost more, but for pod types passing my value will never cost more than by reference.

So yeah, your both wrong.