mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Document pure functions
This commit is contained in:
		
							parent
							
								
									e9a9a07d94
								
							
						
					
					
						commit
						93e6e83093
					
				| @ -475,7 +475,7 @@ Functions can be declared ``view`` in which case they promise not to modify the | ||||
| 
 | ||||
|     contract C { | ||||
|         function f(uint a, uint b) view returns (uint) { | ||||
|             return a * (b + 42); | ||||
|             return a * (b + 42) + now; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -488,6 +488,27 @@ Functions can be declared ``view`` in which case they promise not to modify the | ||||
| .. warning:: | ||||
|   The compiler does not enforce yet that a ``view`` method is not modifying state. | ||||
| 
 | ||||
| .. _pure-functions: | ||||
| 
 | ||||
| ************** | ||||
| Pure Functions | ||||
| ************** | ||||
| 
 | ||||
| Functions can be declared ``pure`` in which case they promise not to read from or modify the state. | ||||
| 
 | ||||
| :: | ||||
| 
 | ||||
|     pragma solidity ^0.4.0; | ||||
| 
 | ||||
|     contract C { | ||||
|         function f(uint a, uint b) pure returns (uint) { | ||||
|             return a * (b + 42); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| .. warning:: | ||||
|   The compiler does not enforce yet that a ``pure`` method is not reading from the state. | ||||
| 
 | ||||
| .. index:: ! fallback function, function;fallback | ||||
| 
 | ||||
| .. _fallback-function: | ||||
|  | ||||
| @ -500,12 +500,13 @@ Function Visibility Specifiers | ||||
| - ``internal``: only visible internally | ||||
| 
 | ||||
| 
 | ||||
| .. index:: modifiers, constant, anonymous, indexed | ||||
| .. index:: modifiers, pure, view, payable, constant, anonymous, indexed | ||||
| 
 | ||||
| Modifiers | ||||
| ========= | ||||
| 
 | ||||
| - ``view`` for functions: Disallow modification of state - this is not enforced yet. | ||||
| - ``pure`` for functions: Disallows modification or access of state - this is not enforced yet. | ||||
| - ``view`` for functions: Disallows modification of state - this is not enforced yet. | ||||
| - ``payable`` for functions: Allows them to receive Ether together with a call. | ||||
| - ``constant`` for state variables: Disallows assignment (except initialisation), does not occupy storage slot. | ||||
| - ``constant`` for functions: Same as ``view``. | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user