aboutsummaryrefslogtreecommitdiffstats
path: root/docs/frequently-asked-questions.rst
diff options
context:
space:
mode:
authorwbt <wbt@users.noreply.github.com>2018-01-23 22:44:37 +0800
committerGitHub <noreply@github.com>2018-01-23 22:44:37 +0800
commit761eae2499b172334e5ea3e75573af99fae2a975 (patch)
tree3ec324015e8d97e9b7ca43cb4dcc3c46b1b3bf31 /docs/frequently-asked-questions.rst
parent7c69d88f937324b64ed8825f9e611e417421434b (diff)
parente5def2da3d9b6cffbff42e2c9e1941831d2fe5ea (diff)
downloaddexon-solidity-761eae2499b172334e5ea3e75573af99fae2a975.tar.gz
dexon-solidity-761eae2499b172334e5ea3e75573af99fae2a975.tar.zst
dexon-solidity-761eae2499b172334e5ea3e75573af99fae2a975.zip
Update from official repo
Diffstat (limited to 'docs/frequently-asked-questions.rst')
-rw-r--r--docs/frequently-asked-questions.rst40
1 files changed, 21 insertions, 19 deletions
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index 5c427c69..7c934041 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -111,10 +111,10 @@ array in the return statement. Pretty cool, huh?
Example::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.16;
contract C {
- function f() returns (uint8[5]) {
+ function f() public pure returns (uint8[5]) {
string[4] memory adaArr = ["This", "is", "an", "array"];
return ([1, 2, 3, 4, 5]);
}
@@ -190,11 +190,11 @@ you should always convert it to a ``bytes`` first::
contract C {
string s;
- function append(byte c) {
+ function append(byte c) public {
bytes(s).push(c);
}
- function set(uint i, byte c) {
+ function set(uint i, byte c) public {
bytes(s)[i] = c;
}
}
@@ -232,12 +232,14 @@ situation.
If you do not want to throw, you can return a pair::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.16;
contract C {
uint[] counters;
function getCounter(uint index)
+ public
+ view
returns (uint counter, bool error) {
if (index >= counters.length)
return (0, true);
@@ -245,7 +247,7 @@ If you do not want to throw, you can return a pair::
return (counters[index], false);
}
- function checkCounter(uint index) {
+ function checkCounter(uint index) public view {
var (counter, error) = getCounter(index);
if (error) {
// ...
@@ -316,11 +318,11 @@ Example::
uint[] data1;
uint[] data2;
- function appendOne() {
+ function appendOne() public {
append(data1);
}
- function appendTwo() {
+ function appendTwo() public {
append(data2);
}
@@ -349,7 +351,7 @@ be created in memory, although it will be created in storage::
uint someVariable;
uint[] data;
- function f() {
+ function f() public {
uint[] x;
x.push(2);
data = x;
@@ -375,7 +377,7 @@ The correct way to do this is the following::
uint someVariable;
uint[] data;
- function f() {
+ function f() public {
uint[] x = data;
x.push(2);
}
@@ -431,14 +433,14 @@ What happens to a ``struct``'s mapping when copying over a ``struct``?
This is a very interesting question. Suppose that we have a contract field set up like such::
- struct user {
+ struct User {
mapping(string => string) comments;
}
- function somefunction {
- user user1;
+ function somefunction public {
+ User user1;
user1.comments["Hello"] = "World";
- user user2 = user1;
+ User user2 = user1;
}
In this case, the mapping of the struct being copied over into the userList is ignored as there is no "list of mapped keys".
@@ -456,13 +458,13 @@ In this example::
pragma solidity ^0.4.0;
contract B {
- function B() payable {}
+ function B() public payable {}
}
contract A {
address child;
- function test() {
+ function test() public {
child = (new B).value(10)(); //construct a new B with 10 wei
}
}
@@ -501,17 +503,17 @@ Can a contract pass an array (static size) or string or ``bytes`` (dynamic size)
Sure. Take care that if you cross the memory / storage boundary,
independent copies will be created::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.16;
contract C {
uint[20] x;
- function f() {
+ function f() public {
g(x);
h(x);
}
- function g(uint[20] y) internal {
+ function g(uint[20] y) internal pure {
y[2] = 3;
}