mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #964 from Denton-L/fix-documentation
Fix documentation
This commit is contained in:
commit
0b89e1e98c
@ -195,45 +195,47 @@ return parameter list for functions.
|
|||||||
uint public data;
|
uint public data;
|
||||||
}
|
}
|
||||||
|
|
||||||
An other contract ``D`` can call ``c.getData()`` to retrieve the value of data in state
|
In the following example, ``D``, can call ``c.getData()`` to retrieve the value of
|
||||||
storage and is not able to call ``f``. Contract ``E`` is derived from ``C`` and can call
|
``data`` in state storage, but is not able to call ``f``. Contract ``E`` is derived from
|
||||||
``compute``.
|
``C`` and, thus, can call ``compute``.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
|
uint private data;
|
||||||
|
|
||||||
function f(uint a) private returns(uint b) { return a + 1; }
|
function f(uint a) private returns(uint b) { return a + 1; }
|
||||||
function setData(uint a) { data = a; }
|
function setData(uint a) { data = a; }
|
||||||
function getData() public returns(uint) {return data;}
|
function getData() public returns(uint) { return data; }
|
||||||
function compute(uint a, uint b) internal returns (uint) { return a+b;}
|
function compute(uint a, uint b) internal returns (uint) { return a+b; }
|
||||||
uint private data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract D {
|
contract D {
|
||||||
function readData() {
|
function readData() {
|
||||||
C c = new C();
|
C c = new C();
|
||||||
local = c.f(7); // error: member "f" is not visible
|
uint local = c.f(7); // error: member "f" is not visible
|
||||||
c.setData(3);
|
c.setData(3);
|
||||||
uint local = c.getData();
|
local = c.getData();
|
||||||
local = c.compute(3,5); // error: member "compute" is not visible
|
local = c.compute(3, 5); // error: member "compute" is not visible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract E is C {
|
contract E is C {
|
||||||
function g() {
|
function g() {
|
||||||
C c = new C();
|
C c = new C();
|
||||||
uint val = compute(3,5); // acces to internal member (from derivated to parent contract)
|
uint val = compute(3, 5); // acces to internal member (from derivated to parent contract)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.. index:: ! accessor;function, ! function;accessor
|
.. index:: ! accessor;function, ! function;accessor
|
||||||
|
|
||||||
Accessor Functions
|
Accessor Functions
|
||||||
==================
|
==================
|
||||||
|
|
||||||
The compiler automatically creates accessor functions for
|
The compiler automatically creates accessor functions for
|
||||||
all public state variables. For the contract given below the compiler will
|
all public state variables. For the contract given below, the compiler will
|
||||||
generate a function called ``data`` that does not take any
|
generate a function called ``data`` that does not take any
|
||||||
arguments and returns a ``uint``, the value of the state
|
arguments and returns a ``uint``, the value of the state
|
||||||
variable ``data``. The initialization of state variables can
|
variable ``data``. The initialization of state variables can
|
||||||
@ -245,6 +247,7 @@ be done at declaration.
|
|||||||
uint public data = 42;
|
uint public data = 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Caller {
|
contract Caller {
|
||||||
C c = new C();
|
C c = new C();
|
||||||
function f() {
|
function f() {
|
||||||
@ -254,8 +257,8 @@ be done at declaration.
|
|||||||
|
|
||||||
The accessor functions have external visibility. If the
|
The accessor functions have external visibility. If the
|
||||||
symbol is accessed internally (i.e. without ``this.``),
|
symbol is accessed internally (i.e. without ``this.``),
|
||||||
it is evaluated as state variable and if it is accessed externally
|
it is evaluated as a state variable and if it is accessed externally
|
||||||
(i.e. with ``this.``), it is evaluated as function.
|
(i.e. with ``this.``), it is evaluated as a function.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ Discontinued:
|
|||||||
|
|
||||||
|
|
||||||
Solidity Tools
|
Solidity Tools
|
||||||
-------------------------------
|
--------------
|
||||||
|
|
||||||
* `Solidity REPL <https://github.com/raineorshine/solidity-repl>`_
|
* `Solidity REPL <https://github.com/raineorshine/solidity-repl>`_
|
||||||
Try Solidity instantly with a command-line Solidity console.
|
Try Solidity instantly with a command-line Solidity console.
|
||||||
|
@ -93,18 +93,18 @@ you should fork Solidity and add your personal fork as a second remote:
|
|||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
cd solidity
|
cd solidity
|
||||||
git remote add personal git@github.com:[username]/solidity.git
|
git remote add personal git@github.com:\<username\>/solidity.git
|
||||||
|
|
||||||
|
|
||||||
Prerequisites - macOS
|
Prerequisites - macOS
|
||||||
----------------------
|
---------------------
|
||||||
|
|
||||||
For macOS, ensure that you have the latest version of
|
For macOS, ensure that you have the latest version of
|
||||||
`xcode installed <https://developer.apple.com/xcode/download/>`_.
|
`Xcode installed <https://developer.apple.com/xcode/download/>`_.
|
||||||
This contains the `Clang C++ compiler <https://en.wikipedia.org/wiki/Clang>`_, the
|
This contains the `Clang C++ compiler <https://en.wikipedia.org/wiki/Clang>`_, the
|
||||||
`xcode IDE <https://en.wikipedia.org/wiki/Xcode>`_ and other Apple development
|
`Xcode IDE <https://en.wikipedia.org/wiki/Xcode>`_ and other Apple development
|
||||||
tools which are required for building C++ applications on OS X.
|
tools which are required for building C++ applications on OS X.
|
||||||
If you are installing xcode for the first time, or have just installed a new
|
If you are installing Xcode for the first time, or have just installed a new
|
||||||
version then you will need to agree to the license before you can do
|
version then you will need to agree to the license before you can do
|
||||||
command-line builds:
|
command-line builds:
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ if you ever want to start again from scratch.
|
|||||||
|
|
||||||
|
|
||||||
Prerequisites - Windows
|
Prerequisites - Windows
|
||||||
------------------------
|
-----------------------
|
||||||
|
|
||||||
You will need to install the following dependencies for Windows builds of Solidity:
|
You will need to install the following dependencies for Windows builds of Solidity:
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ manual process, but is now a one-liner:
|
|||||||
|
|
||||||
Or, on Windows:
|
Or, on Windows:
|
||||||
|
|
||||||
.. code:: bash
|
.. code:: bat
|
||||||
|
|
||||||
scripts\install_deps.bat
|
scripts\install_deps.bat
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ only the person holding the keys to the account can transfer money from it.
|
|||||||
Blocks
|
Blocks
|
||||||
======
|
======
|
||||||
|
|
||||||
One major obstacle to overcome is what, in Bitcoin terms, is called "double-spend attack":
|
One major obstacle to overcome is what, in Bitcoin terms, is called a "double-spend attack":
|
||||||
What happens if two transactions exist in the network that both want to empty an account,
|
What happens if two transactions exist in the network that both want to empty an account,
|
||||||
a so-called conflict?
|
a so-called conflict?
|
||||||
|
|
||||||
@ -444,13 +444,13 @@ receives the address of the new contract on the stack.
|
|||||||
|
|
||||||
.. index:: selfdestruct
|
.. index:: selfdestruct
|
||||||
|
|
||||||
Selfdestruct
|
``selfdestruct``
|
||||||
============
|
================
|
||||||
|
|
||||||
The only possibility that code is removed from the blockchain is
|
The only possibility that code is removed from the blockchain is
|
||||||
when a contract at that address performs the ``SELFDESTRUCT`` operation.
|
when a contract at that address performs the ``selfdestruct`` operation.
|
||||||
The remaining Ether stored at that address is sent to a designated
|
The remaining Ether stored at that address is sent to a designated
|
||||||
target and then the storage and code is removed.
|
target and then the storage and code is removed.
|
||||||
|
|
||||||
Note that even if a contract's code does not contain the ``SELFDESTRUCT``
|
Note that even if a contract's code does not contain a call to ``selfdestruct``,
|
||||||
opcode, it can still perform that operation using delegatecall or callcode.
|
it can still perform that operation using ``delegatecall`` or ``callcode``.
|
||||||
|
@ -661,13 +661,18 @@ Explicit Conversions
|
|||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
If the compiler does not allow implicit conversion but you know what you are
|
If the compiler does not allow implicit conversion but you know what you are
|
||||||
doing, an explicit type conversion is sometimes possible::
|
doing, an explicit type conversion is sometimes possible. Note that this may
|
||||||
|
give you some unexpected behaviour so be sure to test to ensure that the
|
||||||
|
result is what you want! Take the following example where you are converting
|
||||||
|
a negative ``int8`` to a ``uint``:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
int8 y = -3;
|
int8 y = -3;
|
||||||
uint x = uint(y);
|
uint x = uint(y);
|
||||||
|
|
||||||
At the end of this code snippet, ``x`` will have the value ``0xfffff..fd`` (64 hex
|
At the end of this code snippet, ``x`` will have the value ``0xfffff..fd`` (64 hex
|
||||||
characters), which is -3 in two's complement representation of 256 bits.
|
characters), which is -3 in the two's complement representation of 256 bits.
|
||||||
|
|
||||||
If a type is explicitly converted to a smaller type, higher-order bits are
|
If a type is explicitly converted to a smaller type, higher-order bits are
|
||||||
cut off::
|
cut off::
|
||||||
|
Loading…
Reference in New Issue
Block a user