This is a creation in Article, where the information may have evolved or changed. Directory (?) [-]
- Key words
- Operator
- Variable
- Pointer
- Function
- return value
- Closed Package
- PO
- Programming specifications
- Oo
- Concurrent
- Project Management
For the markdown compiler does not have the automatic saving function this thing, I express serious disgust. One hours of tidying up to naught, and incredibly can not be imported into the HTML editor, really unbearable!
Key words
category |
C |
Go |
Character |
Char |
No |
String |
No |
String |
Floating point number |
Double, float |
float32, Float64, complex64, complex128 |
Integer |
int long Short |
Uint8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, uint, int, uintptr, byte = Uint8, Rune=unit32 |
bool |
No |
Boolean true, False |
Function |
No |
Func |
Interface |
No |
Interface |
Empty |
void |
No |
Any |
No |
interface{} |
Polymerization |
Enum, struct, union |
struct |
Symbol Qualification Symbol |
Signed, unsigned, auto, const, extern, register, Static, volatile |
Auto, const |
Process Control |
Break, case, does, for, Goto, if, else, continue, default, return, switch, while |
For, if, else, goto, break, switch, case, default, Fallthrough, range, select, Range |
Data |
No |
Map |
Other |
sizeof, typedef |
Iota, Var, type, defer, go Chan, package, import |
Operator
function |
C |
Go |
Take counter |
~ |
^ |
Choose |
? : |
|
Fetching pointer content |
-> |
|
Write read-out |
|
<- -> |
Initialize and assign values |
|
:= |
The rest of the operators are basically the same
Variable
X |
C |
Go |
Declaration/definition |
TYPE NAMEint i |
(Var) NAME TYPEvar i int |
Character (String) |
char , char [] |
byte byte[], string |
Shaping bit width |
relies on specific platforms and compilers |
You can specify a width, or you can rely on the platform compiler |
Valid range |
The variables opened up on the stack are valid in scope, and the variables that are opened on the heap are manually released before |
The last reference is valid before it leaves the scope |
Scope control |
Static limit is valid for this file, extern looks for global variables for other files |
Uppercase start can be exported, lowercase only for this package use |
Pointer
The Assumption a
is a pointer to a struct in which a member is called b
.
- The pointer
&
operator *
and the pointer operator are the same.
- In the pointer comparison, nil in Go is equivalent to the C language of NULL.
Function
return value
C |
Go |
There can only be one |
can have multiple |
Like what:
func exchange( a int , b int ) ( int , int ){ return b , a}
Closed Package
C-language functions and variables are two different concepts, and variables can only be identified by a function pointer in the form of a function.
The function of the Go language is also a variable.
Try the following code:
Package MainImport "FMT" func getfunc () func (int) int {i: = 0 //this variable is bound to the following return function return increment_i (J int) int {i + = j; return I}} func Main () {func_i1: = Getfunc () Func_i2: = Getfunc () // Above two call Getfunc, get two increment_i functions, each binding their own I variable for I: =0; I < 10; i++ {fmt. Println ( "FUNC1 print:", FUNC_I1 (i)) fmt. Println ( "FUNC2 print:", Func_i2 (I+1))}}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
PO
X |
C |
Go |
If |
"if (condition) xxx else xxx" ' |
"' If condition {xxx} else {xxx} ' |
Switch |
Can only choose to be converted to reshape, case without break automatically continue |
Can be of any type and will not automatically continue unless Failthrough is used |
Select |
It's a function. |
keyword, select chan |
For |
for (;;) Xxx |
for; {XXX} |
While |
Yes |
No |
Do ... while |
Yes |
No |
Programming specifications
- No semicolon required at the end of sentence
- The If for code snippet must be surrounded by curly braces
- If the condition not parentheses
- The for indication section does not have parentheses
- The left curly brace cannot be self-line
Oo
- Method
Between the keyword Func and the function name the description belongs to that struct.
struct { a int}func ( this * OOTest) GetAByPointer() int { return this.a}func ( this OOTest) GetAByCopy() int { return this.a}
- Interface
defining interfaces, explaining function types
type IOOTest interface { GetAByPointer() int }
The interface object is assigned to the struct object pointer that implements the corresponding interface when used.
var i_test IOOTestvar test OOTest i_test = &test
type OOTest1 struct{ OOTest b int}
This OOTest1
will have OOTest
the member variables and methods
Concurrent
X |
C + + |
Go |
Realize |
Threads that depend on the system interface |
Go keyword, goroutine co-process |
Lock |
Rely on system supply or library or own implementation |
Sync Pack |
Communication |
Shared Memory/Message |
Message chan mechanism |
Project Management
X |
C + + |
Go |
Compiler |
Self-selection |
Comes with |
Engineering Management |
Self-selection |
Comes with |
Testing mechanism |
Self-selection |
Comes with |
Unified encoding Format |
Reliance on programmer Awareness |
Tools for Unified Finishing |
Original address
http://studygolang.com/wr?u=http%3a%2f%2fblog.csdn.net%2fcchd0001%2farticle%2fdetails%2f44982127