简体   繁体   中英

What does mean expression "variableName;" in Solidity?

I can not find any information about this expression in docs. There is the following code on Ehternaut Re-entrancy task .

function withdraw(uint _amount) public {
  if(balances[msg.sender] >= _amount) {
    (bool result,) = msg.sender.call{value:_amount}("");
    if(result) {
      _amount;
    }
    balances[msg.sender] -= _amount;
  }
}

What does _amount; mean?

if(result) {
  _amount;
}

This snippet effectively does nothing. You can safely ignore it, as it's not related to the reentrancy vulnerability.

Without the mentioned snippet, the compiler would raise a warning about unused result variable. If they didn't declare the result variable, there would be another warning about not checking the result of the low-level call. And if they just left the condition block empty - yes, another warning about empty block.

So my best guess is that the authors just wanted to clear the warnings, and chose this way to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM