Q:

Is there any gas cost when executing `msg.sender.transfer(0)`?

I have a function which looks more or less like this:
function exchange(uint256 amount, bool specialCase) external returns (uint256) {
    let retVal;
    if (specialCase) {
        register(amount);
        retVal = 0;
    }
    else if (amount > address(this).balance) {
        register(amount - address(this).balance);
        retVal = address(this).balance;
    }
    else {
        register(0);
        retVal = amount;
    }
    require(authorized(msg.sender));
    msg.sender.transfer(retVal);
    return retVal;
}

As you can see, in some cases, it will execute msg.sender.transfer(0).
Of course, I can avoid this by placing msg.sender.transfer(retVal) only where retVal > 0.
But I think that my code looks "cleaner" this way, and I would like to keep it as is.
So I would like to know if there is any gas cost in executing msg.sender.transfer(0).
Thank you!!!

A:

It cost about 1200 gas according to remix.
using this contract:
contract test  {
    address user = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c;

    function send() public {
        user.transfer(0);
    }
}

Produces a transaction cost of 22381 gas, with execution cost of  1173 gas 
Changing the value of the transfer to anything different from zero (note that the contract must have a positive balance) make the execution cost about 8000.
Hope this helps

