{{code "/doc/progs/cgo1.go" `/package rand/` `/END/`}}
<p>
-Let’s look at what's happening here, starting with the import statement.
+Let's look at what's happening here, starting with the import statement.
</p>
<p>
{{code "/doc/progs/cgo1.go" `/func Random/` `/STOP/`}}
<p>
-Here’s an equivalent function that uses a temporary variable to illustrate
+Here's an equivalent function that uses a temporary variable to illustrate
the type conversion more explicitly:
</p>
{{code "/doc/progs/cgo1.go" `/\/\*/` `/STOP/`}}
<p>
-Cgo recognizes this comment and uses it as a header when compiling the C
-parts of the package. In this case it is just a simple include statement,
-but it can be any valid C code. The comment must be immediately before the
-line that imports <code>"C"</code>, without any intervening blank lines,
-just like a documentation comment.
+Cgo recognizes this comment. Any lines starting
+with <code>#cgo</code>
+followed
+by a space character are removed; these become directives for cgo.
+The remaining lines are used as a header when compiling the C parts of
+the package. In this case those lines are just a
+single <code>#include</code>
+statement, but they can be almost any C code. The <code>#cgo</code>
+directives are
+used to provide flags for the compiler and linker when building the C
+parts of the package.
+</p>
+
+<p>
+There is a limitation: if your program uses any <code>//export</code>
+directives, then the C code in the comment may only include declarations
+(<code>extern int f();</code>), not definitions (<code>int f() {
+return 1; }</code>). You can use <code>//export</code> directives to
+make Go functions accessible to C code.
+</p>
+
+<p>
+The <code>#cgo</code> and <code>//export</code> directives are
+documented in
+the <a href="/cmd/cgo/">cgo documentation</a>.
</p>
<p>
</p>
<p>
-Unlike Go, C doesn’t have an explicit string type. Strings in C are
+Unlike Go, C doesn't have an explicit string type. Strings in C are
represented by a zero-terminated array of chars.
</p>
<p>
Memory allocations made by C code are not known to Go's memory manager.
When you create a C string with <code>C.CString</code> (or any C memory
-allocation) you must remember to free the memory when you’re done with it
+allocation) you must remember to free the memory when you're done with it
by calling <code>C.free</code>.
</p>
</p>
<p>
-For a simple, idiomatic example of a cgo-based package, see Russ Cox’s <a
+For a simple, idiomatic example of a cgo-based package, see Russ Cox's <a
href="http://code.google.com/p/gosqlite/source/browse/sqlite/sqlite.go">gosqlite</a>.
Also, the Go Project Dashboard lists <a
href="https://godashboard.appspot.com/project?tag=cgo">several other
</p>
<p>
-Finally, if you’re curious as to how all this works internally, take a look
-at the introductory comment of the runtime package’s <a href="/src/pkg/runtime/cgocall.c">cgocall.c</a>.
+Finally, if you're curious as to how all this works internally, take a look
+at the introductory comment of the runtime package's <a href="/src/pkg/runtime/cgocall.c">cgocall.c</a>.
</p>