Created
January 30, 2019 09:03
-
-
Save lyhistory/bde8b0a967c7dae1fe7dadf302812e99 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.0 <0.6.0; | |
contract DeleteExample { | |
uint data; | |
uint[] dataArray; | |
function f() public { | |
uint x = data; | |
delete x; //sets x to 0, does not affect data | |
delete data; // sets data to 0, does not affect x | |
uint[] storage y = dataArray; | |
delete dataArray; // this sets dataArray.length to zero, but as uint[] is a complex object, also | |
// y is affected which is an alias to the storage object | |
// On the other hand: "delete y" is not valid, as assignments to local variables | |
// referencing storage objects can only be made from existing storage objects. | |
assert(y.length==0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment