Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
4a903e0b
Commit
4a903e0b
authored
Jan 27, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
defer statement
R=r DELTA=30 (26 added, 0 deleted, 4 changed) OCL=23533 CL=23569
parent
fa615a3b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
go_spec.txt
doc/go_spec.txt
+30
-4
No files found.
doc/go_spec.txt
View file @
4a903e0b
...
...
@@ -3,7 +3,7 @@ The Go Programming Language Specification (DRAFT)
Robert Griesemer, Rob Pike, Ken Thompson
(January 2
3
, 2009)
(January 2
6
, 2009)
----
...
...
@@ -235,6 +235,7 @@ Contents
Continue statements
Label declaration
Goto statements
Defer statements
Function declarations
Method declarations
...
...
@@ -682,8 +683,8 @@ Reserved words
The following words are reserved and must not be used as identifiers:
break default func interface select
case
else
go map struct
chan
goto package switch
case
defer
go map struct
chan
else
goto package switch
const fallthrough if range type
continue for import return var
...
...
@@ -2501,7 +2502,8 @@ Statements control execution.
Statement =
Declaration | LabelDecl | EmptyStat |
SimpleStat | GoStat | ReturnStat | BreakStat | ContinueStat | GotoStat |
FallthroughStat | Block | IfStat | SwitchStat | SelectStat | ForStat .
FallthroughStat | Block | IfStat | SwitchStat | SelectStat | ForStat |
DeferStat .
SimpleStat =
ExpressionStat | IncDecStat | Assignment | SimpleVarDecl .
...
...
@@ -3015,6 +3017,30 @@ clause of the switch statement.
FallthroughStat = "fallthrough" .
Defer statements
----
A defer statement invokes a function whose execution is deferred to the moment
when the surrounding function returns.
DeferStat = "defer" Expression .
The expression must be a function call. Each time the defer statement executes,
the parameters to the function call are evaluated and saved anew but the
function is not invoked. Immediately before the innermost function surrounding
the defer statement returns, but after its return value (if any) is evaluated,
each deferred function is executed with its saved parameters. Deferred functions
are executed in LIFO order.
lock(l);
defer unlock(l); // unlocking happens before surrounding function returns
// prints 3 2 1 0 before surrounding function returns
for i := 0; i <= 3; i++ {
defer print(i);
}
----
Function declarations
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment