]> Cypherpunks repositories - gostls13.git/commitdiff
doc/articles: use C90 standard functions in the cgo article.
authorShenghou Ma <minux.ma@gmail.com>
Mon, 3 Jun 2013 17:40:53 +0000 (01:40 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Mon, 3 Jun 2013 17:40:53 +0000 (01:40 +0800)
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/9953043

doc/articles/c_go_cgo.html
doc/progs/cgo1.go
doc/progs/cgo2.go

index b37a6ba65b1a6bb967939e527ba1f3fa7a010928..4b04bb49e801af3dc4dcca2f76c682655a8cd63c 100644 (file)
@@ -11,8 +11,8 @@ single Go package.
 
 <p>
 To lead with an example, here's a Go package that provides two functions -
-<code>Random</code> and <code>Seed</code> - that wrap C's <code>random</code>
-and <code>srandom</code> functions.
+<code>Random</code> and <code>Seed</code> - that wrap C's <code>rand</code>
+and <code>srand</code> functions.
 </p>
 
 {{code "/doc/progs/cgo1.go" `/package rand/` `/END/`}}
@@ -30,14 +30,14 @@ name space.
 
 <p>
 The <code>rand</code> package contains four references to the <code>C</code>
-package: the calls to <code>C.random</code> and <code>C.srandom</code>, the
+package: the calls to <code>C.rand</code> and <code>C.srand</code>, the
 conversion <code>C.uint(i)</code>, and the <code>import</code> statement.
 </p>
 
 <p>
 The <code>Random</code> function calls the standard C library's <code>random</code>
-function and returns the result.  In C, <code>random</code> returns a value of the
-C type <code>long</code>, which cgo represents as the type <code>C.long</code>.
+function and returns the result.  In C, <code>rand</code> returns a value of the
+C type <code>int</code>, which cgo represents as the type <code>C.int</code>.
 It must be converted to a Go type before it can be used by Go code outside this
 package, using an ordinary Go type conversion:
 </p>
@@ -54,7 +54,7 @@ the type conversion more explicitly:
 <p>
 The <code>Seed</code> function does the reverse, in a way. It takes a
 regular Go <code>int</code>, converts it to the C <code>unsigned int</code>
-type, and passes it to the C function <code>srandom</code>.
+type, and passes it to the C function <code>srand</code>.
 </p>
 
 {{code "/doc/progs/cgo1.go" `/func Seed/` `/END/`}}
index 1a2dc6c964d806a1ac5c2b81e51e5f53a4a1b74b..805fe3c9c546cca76933b51134f99f444f3f564c 100644 (file)
@@ -12,12 +12,12 @@ import "C"
 
 // STOP OMIT
 func Random() int {
-       return int(C.random())
+       return int(C.rand())
 }
 
 // STOP OMIT
 func Seed(i int) {
-       C.srandom(C.uint(i))
+       C.srand(C.uint(i))
 }
 
 // END OMIT
index 9999af344b925897358bfdc5ea10211791fbc1b9..b9e9f7d9709efac287bfff6261704cc583c7160a 100644 (file)
@@ -11,13 +11,13 @@ package rand2
 import "C"
 
 func Random() int {
-       var r C.long = C.random()
+       var r C.int = C.rand()
        return int(r)
 }
 
 // STOP OMIT
 func Seed(i int) {
-       C.srandom(C.uint(i))
+       C.srand(C.uint(i))
 }
 
 // END OMIT