-
-
Save maurelian/2a8ff9b1f7e3d8c69374f751af960633 to your computer and use it in GitHub Desktop.
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
// fun with arrays | |
pragma solidity ^0.4.10; | |
contract ArrayPops { | |
// create some arrays to check out | |
uint[] public uint_arr; | |
string[] public string_arr; | |
bytes32[] public bytes32_arr; | |
function ArrayPops() { | |
// fill our arrays with arbitrary data | |
uint_arr = [1,2,3,4,5]; | |
string_arr = ['one', 'two', 'three', 'four', 'five']; | |
bytes32_arr = [bytes32(0), bytes32(1), bytes32(2), bytes32(3), bytes32(4)]; | |
} | |
// returns an empty value | |
function broken_pop_string () returns (string) { | |
string member = string_arr[string_arr.length-1]; | |
string_arr.length--; | |
return member; | |
} | |
function pop_string () returns (string member) { | |
member = string_arr[string_arr.length-1]; | |
string_arr.length--; | |
return member; | |
} | |
function pop_uint () returns (uint member) { | |
member = uint_arr[uint_arr.length-1]; | |
uint_arr.length = uint_arr.length-1; | |
return member; | |
} | |
// not actually broken | |
function broken_pop_uint () returns (uint) { | |
uint member = uint_arr[uint_arr.length-1]; | |
uint_arr.length = uint_arr.length-1; | |
return member; | |
} | |
function pop_bytes32 () returns (bytes32 member) { | |
member = bytes32_arr[bytes32_arr.length-1]; | |
bytes32_arr.length = bytes32_arr.length-1; | |
return member; | |
} | |
// not actually broken | |
function broken_pop_bytes32 () returns (bytes32) { | |
bytes32 member = bytes32_arr[bytes32_arr.length-1]; | |
bytes32_arr.length = bytes32_arr.length-1; | |
return member; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment