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
f53db3ea
Commit
f53db3ea
authored
Apr 28, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add description of type conversions.
SVN=116978
parent
1265a0c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
2 deletions
+35
-2
go_lang.txt
doc/go_lang.txt
+35
-2
No files found.
doc/go_lang.txt
View file @
f53db3ea
...
...
@@ -1082,7 +1082,8 @@ Expression syntax is based on that of C but with fewer precedence levels.
Expression "." "(" Type ")" .
Call = Expression "(" [ ExpressionList ] ")" .
Conversion = TypeName "(" [ ExpressionList ] ")" .
Conversion = TypeName "(" Expression ")" |
"convert" "(" Type "," Expression ")" .
Allocation = "new" "(" Type [ "," Expression ] ")" .
binary_op = log_op | rel_op | add_op | mul_op .
...
...
@@ -1211,6 +1212,37 @@ buffered channels, and maps.
TODO: argument order for dimensions in multidimensional arrays
Conversions
----
There are three ways to convert a value from one type to another.
The most general is a call to the intrinsic special function "convert"
with arguments the type name and the value to be converted.
var i int = convert(int, PI * 1000.0);
chars_as_ints := convert([]int, "now is the time");
If the destination type is a known type name, the conversion can be
rewritten to look syntactically like a call to a function with that
name.
i := int(PI * 1000.0);
s := AStructType(an_interface_variable);
A conversion can be written as a parenthesized type after a period.
Although intended for ease of conversion within a method call chain,
this form works in any expression context.
var s *AStructType = vec.index(2).(*AStructType);
fld := vec.index(2).(*AStructType).field;
f := 1000.(float);
TODO: are there parameters to any conversions? go.y has oexpr_list as the
contents of a TypeName() conversion; i expected expr instead and that's what
the others have.
The constant generator 'iota'
----
...
...
@@ -1733,4 +1765,5 @@ TODO
- TODO: type switch?
- TODO: words about slices
- TODO: I (gri) would like to say that sizeof(int) == sizeof(pointer), always.
- TODO: when are two types equal? consider
func iterate(f *func(int, interface{}), arg interface{})
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