@@ -14,27 +14,27 @@ as C.stdout, or functions such as C.putchar.
1414
1515If the import of "C" is immediately preceded by a comment, that
1616comment, called the preamble, is used as a header when compiling
17- the C parts of the package. For example:
17+ the C parts of the package. For example:
1818
1919 // #include <stdio.h>
2020 // #include <errno.h>
2121 import "C"
2222
2323The preamble may contain any C code, including function and variable
24- declarations and definitions. These may then be referred to from Go
25- code as though they were defined in the package "C". All names
24+ declarations and definitions. These may then be referred to from Go
25+ code as though they were defined in the package "C". All names
2626declared in the preamble may be used, even if they start with a
27- lower-case letter. Exception: static variables in the preamble may
27+ lower-case letter. Exception: static variables in the preamble may
2828not be referenced from Go code; static functions are permitted.
2929
30- See $GOROOT/misc/cgo/stdio and $GOROOT/misc/cgo/gmp for examples. See
30+ See $GOROOT/misc/cgo/stdio and $GOROOT/misc/cgo/gmp for examples. See
3131"C? Go? Cgo!" for an introduction to using cgo:
3232https://golang.org/doc/articles/c_go_cgo.html.
3333
3434CFLAGS, CPPFLAGS, CXXFLAGS, FFLAGS and LDFLAGS may be defined with pseudo
3535#cgo directives within these comments to tweak the behavior of the C, C++
36- or Fortran compiler. Values defined in multiple directives are concatenated
37- together. The directive can include a list of build constraints limiting its
36+ or Fortran compiler. Values defined in multiple directives are concatenated
37+ together. The directive can include a list of build constraints limiting its
3838effect to systems satisfying one of the constraints
3939(see https://golang.org/pkg/go/build/#hdr-Build_Constraints for details about the constraint syntax).
4040For example:
@@ -57,16 +57,16 @@ The default pkg-config tool may be changed by setting the PKG_CONFIG environment
5757
5858When building, the CGO_CFLAGS, CGO_CPPFLAGS, CGO_CXXFLAGS, CGO_FFLAGS and
5959CGO_LDFLAGS environment variables are added to the flags derived from
60- these directives. Package-specific flags should be set using the
60+ these directives. Package-specific flags should be set using the
6161directives, not the environment variables, so that builds work in
6262unmodified environments.
6363
6464All the cgo CPPFLAGS and CFLAGS directives in a package are concatenated and
65- used to compile C files in that package. All the CPPFLAGS and CXXFLAGS
65+ used to compile C files in that package. All the CPPFLAGS and CXXFLAGS
6666directives in a package are concatenated and used to compile C++ files in that
67- package. All the CPPFLAGS and FFLAGS directives in a package are concatenated
68- and used to compile Fortran files in that package. All the LDFLAGS directives
69- in any package in the program are concatenated and used at link time. All the
67+ package. All the CPPFLAGS and FFLAGS directives in a package are concatenated
68+ and used to compile Fortran files in that package. All the LDFLAGS directives
69+ in any package in the program are concatenated and used at link time. All the
7070pkg-config directives are concatenated and sent to pkg-config simultaneously
7171to add to each appropriate set of command-line flags.
7272
@@ -84,27 +84,27 @@ Will be expanded to:
8484
8585When the Go tool sees that one or more Go files use the special import
8686"C", it will look for other non-Go files in the directory and compile
87- them as part of the Go package. Any .c, .s, or .S files will be
88- compiled with the C compiler. Any .cc, .cpp, or .cxx files will be
89- compiled with the C++ compiler. Any .f, .F, .for or .f90 files will be
87+ them as part of the Go package. Any .c, .s, or .S files will be
88+ compiled with the C compiler. Any .cc, .cpp, or .cxx files will be
89+ compiled with the C++ compiler. Any .f, .F, .for or .f90 files will be
9090compiled with the fortran compiler. Any .h, .hh, .hpp, or .hxx files will
9191not be compiled separately, but, if these header files are changed,
92- the C and C++ files will be recompiled. The default C and C++
92+ the C and C++ files will be recompiled. The default C and C++
9393compilers may be changed by the CC and CXX environment variables,
9494respectively; those environment variables may include command line
9595options.
9696
9797The cgo tool is enabled by default for native builds on systems where
98- it is expected to work. It is disabled by default when
99- cross-compiling. You can control this by setting the CGO_ENABLED
98+ it is expected to work. It is disabled by default when
99+ cross-compiling. You can control this by setting the CGO_ENABLED
100100environment variable when running the go tool: set it to 1 to enable
101- the use of cgo, and to 0 to disable it. The go tool will set the
101+ the use of cgo, and to 0 to disable it. The go tool will set the
102102build constraint "cgo" if cgo is enabled.
103103
104104When cross-compiling, you must specify a C cross-compiler for cgo to
105- use. You can do this by setting the CC_FOR_TARGET environment
105+ use. You can do this by setting the CC_FOR_TARGET environment
106106variable when building the toolchain using make.bash, or by setting
107- the CC environment variable any time you run the go tool. The
107+ the CC environment variable any time you run the go tool. The
108108CXX_FOR_TARGET and CXX environment variables work in a similar way for
109109C++ code.
110110
@@ -138,7 +138,7 @@ C's union types are represented as a Go byte array with the same length.
138138Go structs cannot embed fields with C types.
139139
140140Go code cannot refer to zero-sized fields that occur at the end of
141- non-empty C structs. To get the address of such a field (which is the
141+ non-empty C structs. To get the address of such a field (which is the
142142only operation you can do with a zero-sized field) you must take the
143143address of the struct and add the size of the struct.
144144
@@ -150,7 +150,7 @@ is different from the same C type used in another.
150150Any C function (even void functions) may be called in a multiple
151151assignment context to retrieve both the return value (if any) and the
152152C errno variable as an error (use _ to skip the result value if the
153- function returns void). For example:
153+ function returns void). For example:
154154
155155 n, err = C.sqrt(-1)
156156 _, err := C.voidFunc()
@@ -187,11 +187,11 @@ received from Go. For example:
187187In C, a function argument written as a fixed size array
188188actually requires a pointer to the first element of the array.
189189C compilers are aware of this calling convention and adjust
190- the call accordingly, but Go cannot. In Go, you must pass
190+ the call accordingly, but Go cannot. In Go, you must pass
191191the pointer to the first element explicitly: C.f(&C.x[0]).
192192
193193A few special functions convert between Go and C types
194- by making copies of the data. In pseudo-Go definitions:
194+ by making copies of the data. In pseudo-Go definitions:
195195
196196 // Go string to C string
197197 // The C string is allocated in the C heap using malloc.
@@ -253,50 +253,50 @@ must be placed in preambles in other files, or in C source files.
253253Passing pointers
254254
255255Go is a garbage collected language, and the garbage collector needs to
256- know the location of every pointer to Go memory. Because of this,
256+ know the location of every pointer to Go memory. Because of this,
257257there are restrictions on passing pointers between Go and C.
258258
259259In this section the term Go pointer means a pointer to memory
260260allocated by Go (such as by using the & operator or calling the
261261predefined new function) and the term C pointer means a pointer to
262- memory allocated by C (such as by a call to C.malloc). Whether a
262+ memory allocated by C (such as by a call to C.malloc). Whether a
263263pointer is a Go pointer or a C pointer is a dynamic property
264264determined by how the memory was allocated; it has nothing to do with
265265the type of the pointer.
266266
267267Go code may pass a Go pointer to C provided the Go memory to which it
268- points does not contain any Go pointers. The C code must preserve
268+ points does not contain any Go pointers. The C code must preserve
269269this property: it must not store any Go pointers in Go memory, even
270- temporarily. When passing a pointer to a field in a struct, the Go
270+ temporarily. When passing a pointer to a field in a struct, the Go
271271memory in question is the memory occupied by the field, not the entire
272- struct. When passing a pointer to an element in an array or slice,
272+ struct. When passing a pointer to an element in an array or slice,
273273the Go memory in question is the entire array or the entire backing
274274array of the slice.
275275
276276C code may not keep a copy of a Go pointer after the call returns.
277277
278- A Go function called by C code may not return a Go pointer. A Go
278+ A Go function called by C code may not return a Go pointer. A Go
279279function called by C code may take C pointers as arguments, and it may
280280store non-pointer or C pointer data through those pointers, but it may
281- not store a Go pointer in memory pointed to by a C pointer. A Go
281+ not store a Go pointer in memory pointed to by a C pointer. A Go
282282function called by C code may take a Go pointer as an argument, but it
283283must preserve the property that the Go memory to which it points does
284284not contain any Go pointers.
285285
286- Go code may not store a Go pointer in C memory. C code may store Go
286+ Go code may not store a Go pointer in C memory. C code may store Go
287287pointers in C memory, subject to the rule above: it must stop storing
288288the Go pointer when the C function returns.
289289
290- These rules are checked dynamically at runtime. The checking is
290+ These rules are checked dynamically at runtime. The checking is
291291controlled by the cgocheck setting of the GODEBUG environment
292- variable. The default setting is GODEBUG=cgocheck=1, which implements
293- reasonably cheap dynamic checks. These checks may be disabled
294- entirely using GODEBUG=cgocheck=0. Complete checking of pointer
292+ variable. The default setting is GODEBUG=cgocheck=1, which implements
293+ reasonably cheap dynamic checks. These checks may be disabled
294+ entirely using GODEBUG=cgocheck=0. Complete checking of pointer
295295handling, at some cost in run time, is available via GODEBUG=cgocheck=2.
296296
297297It is possible to defeat this enforcement by using the unsafe package,
298298and of course there is nothing stopping the C code from doing anything
299- it likes. However, programs that break these rules are likely to fail
299+ it likes. However, programs that break these rules are likely to fail
300300in unexpected and unpredictable ways.
301301
302302Using cgo directly
@@ -499,7 +499,7 @@ Here is a _cgo_gotypes.go containing definitions for needed C types:
499499 type _Ctype_void [0]byte
500500
501501The _cgo_gotypes.go file also contains the definitions of the
502- functions. They all have similar bodies that invoke runtime·cgocall
502+ functions. They all have similar bodies that invoke runtime·cgocall
503503to make a switch from the Go runtime world to the system C (GCC-based)
504504world.
505505
@@ -835,7 +835,7 @@ to avoid conflicts), write the go.o file to that directory, and invoke
835835the host linker. The default value for the host linker is $CC, split
836836into fields, or else "gcc". The specific host linker command line can
837837be overridden using command line flags: cmd/link -extld=clang
838- -extldflags='-ggdb -O3'. If any package in a build includes a .cc or
838+ -extldflags='-ggdb -O3'. If any package in a build includes a .cc or
839839other file compiled by the C++ compiler, the go tool will use the
840840-extld option to set the host linker to the C++ compiler.
841841
0 commit comments