Add version pragma to docs examples

This commit is contained in:
Alex Beregszaszi 2017-07-10 22:58:23 +01:00
parent 9a5aac599e
commit b2fcd59ee6
4 changed files with 16 additions and 0 deletions

View File

@ -182,6 +182,8 @@ Given the contract:
:: ::
pragma solidity ^0.4.0;
contract Foo { contract Foo {
function bar(bytes3[2] xy) {} function bar(bytes3[2] xy) {}
function baz(uint32 x, bool y) returns (bool r) { r = x > 32 || y; } function baz(uint32 x, bool y) returns (bool r) { r = x > 32 || y; }

View File

@ -679,6 +679,8 @@ Example:
We will follow an example compilation from Solidity to desugared assembly. We will follow an example compilation from Solidity to desugared assembly.
We consider the runtime bytecode of the following Solidity program:: We consider the runtime bytecode of the following Solidity program::
pragma solidity ^0.4.0;
contract C { contract C {
function f(uint x) returns (uint y) { function f(uint x) returns (uint y) {
y = 1; y = 1;

View File

@ -20,6 +20,8 @@ For example, suppose we want our contract to
accept one kind of external calls with two integers, we would write accept one kind of external calls with two integers, we would write
something like:: something like::
pragma solidity ^0.4.0;
contract Simple { contract Simple {
function taker(uint _a, uint _b) { function taker(uint _a, uint _b) {
// do something with _a and _b. // do something with _a and _b.
@ -34,6 +36,8 @@ The output parameters can be declared with the same syntax after the
the sum and the product of the two given integers, then we would the sum and the product of the two given integers, then we would
write:: write::
pragma solidity ^0.4.0;
contract Simple { contract Simple {
function arithmetics(uint _a, uint _b) returns (uint o_sum, uint o_product) { function arithmetics(uint _a, uint _b) returns (uint o_sum, uint o_product) {
o_sum = _a + _b; o_sum = _a + _b;
@ -91,6 +95,8 @@ Internal Function Calls
Functions of the current contract can be called directly ("internally"), also recursively, as seen in Functions of the current contract can be called directly ("internally"), also recursively, as seen in
this nonsensical example:: this nonsensical example::
pragma solidity ^0.4.0;
contract C { contract C {
function g(uint a) returns (uint ret) { return f(); } function g(uint a) returns (uint ret) { return f(); }
function f() returns (uint ret) { return g(7) + f(); } function f() returns (uint ret) { return g(7) + f(); }
@ -116,6 +122,8 @@ all function arguments have to be copied to memory.
When calling functions of other contracts, the amount of Wei sent with the call and When calling functions of other contracts, the amount of Wei sent with the call and
the gas can be specified with special options ``.value()`` and ``.gas()``, respectively:: the gas can be specified with special options ``.value()`` and ``.gas()``, respectively::
pragma solidity ^0.4.0;
contract InfoFeed { contract InfoFeed {
function info() payable returns (uint ret) { return 42; } function info() payable returns (uint ret) { return 42; }
} }
@ -261,6 +269,8 @@ Destructuring Assignments and Returning Multiple Values
Solidity internally allows tuple types, i.e. a list of objects of potentially different types whose size is a constant at compile-time. Those tuples can be used to return multiple values at the same time and also assign them to multiple variables (or LValues in general) at the same time:: Solidity internally allows tuple types, i.e. a list of objects of potentially different types whose size is a constant at compile-time. Those tuples can be used to return multiple values at the same time and also assign them to multiple variables (or LValues in general) at the same time::
pragma solidity ^0.4.0;
contract C { contract C {
uint[] data; uint[] data;

View File

@ -48,6 +48,8 @@ non-elementary type, the positions are found by adding an offset of ``keccak256(
So for the following contract snippet:: So for the following contract snippet::
pragma solidity ^0.4.0;
contract C { contract C {
struct s { uint a; uint b; } struct s { uint a; uint b; }
uint x; uint x;