diff options
author | chriseth <chris@ethereum.org> | 2018-07-16 20:04:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-16 20:04:18 +0800 |
commit | c5ff173431741a4b12cac73c10e2132e3e4bb9d5 (patch) | |
tree | f200bf5d35d5ec3467817dcea2d91918e991fe55 /docs/types.rst | |
parent | 1a1cff189bcc9dc9dbd38ab40d6ee445b6128fd3 (diff) | |
parent | 3267adcd14ba10e27a4b177e771fca9c9ab39646 (diff) | |
download | dexon-solidity-c5ff173431741a4b12cac73c10e2132e3e4bb9d5.tar.gz dexon-solidity-c5ff173431741a4b12cac73c10e2132e3e4bb9d5.tar.zst dexon-solidity-c5ff173431741a4b12cac73c10e2132e3e4bb9d5.zip |
Merge pull request #4512 from chase1745/use-explicit-data-locations-external-tests
Added default data locations to docs and other external tests.
Diffstat (limited to 'docs/types.rst')
-rw-r--r-- | docs/types.rst | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/docs/types.rst b/docs/types.rst index 1641b921..0fe36757 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -471,11 +471,11 @@ Another example that uses external function types:: } Request[] requests; event NewRequest(uint); - function query(bytes data, function(bytes memory) external callback) public { + function query(bytes memory data, function(bytes memory) external callback) public { requests.push(Request(data, callback)); emit NewRequest(requests.length - 1); } - function reply(uint requestID, bytes response) public { + function reply(uint requestID, bytes memory response) public { // Here goes the check that the reply comes from a trusted source requests[requestID].callback(response); } @@ -486,7 +486,7 @@ Another example that uses external function types:: function buySomething() { oracle.query("USD", this.oracleResponse); } - function oracleResponse(bytes response) public { + function oracleResponse(bytes memory response) public { require( msg.sender == address(oracle), "Only oracle can call this." @@ -540,7 +540,7 @@ memory-stored reference type do not create a copy. uint[] x; // the data location of x is storage // the data location of memoryArray is memory - function f(uint[] memoryArray) public { + function f(uint[] memory memoryArray) public { x = memoryArray; // works, copies the whole array to storage uint[] storage y = x; // works, assigns a pointer, data location of y is storage y[7]; // fine, returns the 8th element @@ -557,7 +557,7 @@ memory-stored reference type do not create a copy. } function g(uint[] storage storageArray) internal {} - function h(uint[] memoryArray) public {} + function h(uint[] memory memoryArray) public {} } Summary @@ -646,7 +646,7 @@ assigned to a variable right away. function f() public pure { g([uint(1), 2, 3]); } - function g(uint[3] _data) public pure { + function g(uint[3] memory _data) public pure { // ... } } @@ -713,7 +713,7 @@ Members bool[2][] m_pairsOfFlags; // newPairs is stored in memory - the default for function arguments - function setAllFlagPairs(bool[2][] newPairs) public { + function setAllFlagPairs(bool[2][] memory newPairs) public { // assignment to a storage array replaces the complete array m_pairsOfFlags = newPairs; } @@ -739,7 +739,7 @@ Members bytes m_byteData; - function byteArrays(bytes data) public { + function byteArrays(bytes memory data) public { // byte arrays ("bytes") are different as they are stored without padding, // but can be treated identical to "uint8[]" m_byteData = data; @@ -748,11 +748,11 @@ Members delete m_byteData[2]; } - function addFlag(bool[2] flag) public returns (uint) { + function addFlag(bool[2] memory flag) public returns (uint) { return m_pairsOfFlags.push(flag); } - function createMemoryArray(uint size) public pure returns (bytes) { + function createMemoryArray(uint size) public pure returns (bytes memory) { // Dynamic memory arrays are created using `new`: uint[2][] memory arrayOfPairs = new uint[2][](size); // Create a dynamic byte array: |