Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
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
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
doc/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)
...
@@ -3,7 +3,7 @@ The Go Programming Language Specification (DRAFT)
Robert Griesemer, Rob Pike, Ken Thompson
Robert Griesemer, Rob Pike, Ken Thompson
(January 2
3
, 2009)
(January 2
6
, 2009)
----
----
...
@@ -235,6 +235,7 @@ Contents
...
@@ -235,6 +235,7 @@ Contents
Continue statements
Continue statements
Label declaration
Label declaration
Goto statements
Goto statements
Defer statements
Function declarations
Function declarations
Method declarations
Method declarations
...
@@ -682,8 +683,8 @@ Reserved words
...
@@ -682,8 +683,8 @@ Reserved words
The following words are reserved and must not be used as identifiers:
The following words are reserved and must not be used as identifiers:
break default func interface select
break default func interface select
case
else
go map struct
case
defer
go map struct
chan
goto package switch
chan
else
goto package switch
const fallthrough if range type
const fallthrough if range type
continue for import return var
continue for import return var
...
@@ -2501,7 +2502,8 @@ Statements control execution.
...
@@ -2501,7 +2502,8 @@ Statements control execution.
Statement =
Statement =
Declaration | LabelDecl | EmptyStat |
Declaration | LabelDecl | EmptyStat |
SimpleStat | GoStat | ReturnStat | BreakStat | ContinueStat | GotoStat |
SimpleStat | GoStat | ReturnStat | BreakStat | ContinueStat | GotoStat |
FallthroughStat | Block | IfStat | SwitchStat | SelectStat | ForStat .
FallthroughStat | Block | IfStat | SwitchStat | SelectStat | ForStat |
DeferStat .
SimpleStat =
SimpleStat =
ExpressionStat | IncDecStat | Assignment | SimpleVarDecl .
ExpressionStat | IncDecStat | Assignment | SimpleVarDecl .
...
@@ -3015,6 +3017,30 @@ clause of the switch statement.
...
@@ -3015,6 +3017,30 @@ clause of the switch statement.
FallthroughStat = "fallthrough" .
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
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