From 022818c142ebc62da9a0e3a86c728ab36c047027 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Tue, 4 Jun 2013 01:40:53 +0800 Subject: [PATCH] doc/articles: use C90 standard functions in the cgo article. R=golang-dev, iant CC=golang-dev https://golang.org/cl/9953043 --- doc/articles/c_go_cgo.html | 12 ++++++------ doc/progs/cgo1.go | 4 ++-- doc/progs/cgo2.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/articles/c_go_cgo.html b/doc/articles/c_go_cgo.html index b37a6ba65b..4b04bb49e8 100644 --- a/doc/articles/c_go_cgo.html +++ b/doc/articles/c_go_cgo.html @@ -11,8 +11,8 @@ single Go package.

To lead with an example, here's a Go package that provides two functions - -Random and Seed - that wrap C's random -and srandom functions. +Random and Seed - that wrap C's rand +and srand functions.

{{code "/doc/progs/cgo1.go" `/package rand/` `/END/`}} @@ -30,14 +30,14 @@ name space.

The rand package contains four references to the C -package: the calls to C.random and C.srandom, the +package: the calls to C.rand and C.srand, the conversion C.uint(i), and the import statement.

The Random function calls the standard C library's random -function and returns the result. In C, random returns a value of the -C type long, which cgo represents as the type C.long. +function and returns the result. In C, rand returns a value of the +C type int, which cgo represents as the type C.int. 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:

@@ -54,7 +54,7 @@ the type conversion more explicitly:

The Seed function does the reverse, in a way. It takes a regular Go int, converts it to the C unsigned int -type, and passes it to the C function srandom. +type, and passes it to the C function srand.

{{code "/doc/progs/cgo1.go" `/func Seed/` `/END/`}} diff --git a/doc/progs/cgo1.go b/doc/progs/cgo1.go index 1a2dc6c964..805fe3c9c5 100644 --- a/doc/progs/cgo1.go +++ b/doc/progs/cgo1.go @@ -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 diff --git a/doc/progs/cgo2.go b/doc/progs/cgo2.go index 9999af344b..b9e9f7d970 100644 --- a/doc/progs/cgo2.go +++ b/doc/progs/cgo2.go @@ -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 -- 2.48.1