LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 | 6 |
7 Cgo enables the creation of Go packages that call C code. | 7 Cgo enables the creation of Go packages that call C code. |
8 | 8 |
9 Usage: | 9 Usage: |
10 go tool cgo [compiler options] file.go | 10 go tool cgo [compiler options] file.go |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 To access a struct, union, or enum type directly, prefix it with | 63 To access a struct, union, or enum type directly, prefix it with |
64 struct_, union_, or enum_, as in C.struct_stat. | 64 struct_, union_, or enum_, as in C.struct_stat. |
65 | 65 |
66 Go structs cannot embed fields with C types. | 66 Go structs cannot embed fields with C types. |
67 | 67 |
68 Any C function (even void functions) may be called in a multiple | 68 Any C function (even void functions) may be called in a multiple |
69 assignment context to retrieve both the return value (if any) and the | 69 assignment context to retrieve both the return value (if any) and the |
70 C errno variable as an error (use _ to skip the result value if the | 70 C errno variable as an error (use _ to skip the result value if the |
71 function returns void). For example: | 71 function returns void). For example: |
72 | 72 |
73 » n, err := C.strtol(C.CString("10"), nil, 50) // base too large | 73 » n, err := C.sqrt(-1) |
74 _, err := C.voidFunc() | 74 _, err := C.voidFunc() |
75 | 75 |
76 In C, a function argument written as a fixed size array | 76 In C, a function argument written as a fixed size array |
77 actually requires a pointer to the first element of the array. | 77 actually requires a pointer to the first element of the array. |
78 C compilers are aware of this calling convention and adjust | 78 C compilers are aware of this calling convention and adjust |
79 the call accordingly, but Go cannot. In Go, you must pass | 79 the call accordingly, but Go cannot. In Go, you must pass |
80 the pointer to the first element explicitly: C.f(&x[0]). | 80 the pointer to the first element explicitly: C.f(&x[0]). |
81 | 81 |
82 A few special functions convert between Go and C types | 82 A few special functions convert between Go and C types |
83 by making copies of the data. In pseudo-Go definitions: | 83 by making copies of the data. In pseudo-Go definitions: |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 to avoid conflicts), write the go.o file to that directory, and invoke | 623 to avoid conflicts), write the go.o file to that directory, and invoke |
624 the host linker. The default value for the host linker is $CC, split | 624 the host linker. The default value for the host linker is $CC, split |
625 into fields, or else "gcc". The specific host linker command line can | 625 into fields, or else "gcc". The specific host linker command line can |
626 be overridden using a command line flag: 6l -hostld='gcc -ggdb' | 626 be overridden using a command line flag: 6l -hostld='gcc -ggdb' |
627 | 627 |
628 These defaults mean that Go-aware build systems can ignore the linking | 628 These defaults mean that Go-aware build systems can ignore the linking |
629 changes and keep running plain '6l' and get reasonable results, but | 629 changes and keep running plain '6l' and get reasonable results, but |
630 they can also control the linking details if desired. | 630 they can also control the linking details if desired. |
631 | 631 |
632 */ | 632 */ |
LEFT | RIGHT |