You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CGO file referring to string.h and using the memcpy function gives the following error:
cannot use (type C.size_t) as type C.ulong in function argument
Sample Code:
package main
/*
#include <stdlib.h>
#include <string.h>
*/
import "C"
import (
"unsafe"
"fmt"
)
func main() {
var ksiz C.size_t
ksiz = C.size_t(6)
k := make([]byte, ksiz)
kp := C.CString("string")
C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), C.ulong(ksiz))
fmt.Println(k)
}
What is the expected output?
Compilation without error. Output:
[115 116 114 105 110 103]
What do you see instead?
# command-line-arguments
./memcpytest.go:17: cannot use ksiz (type C.size_t) as type C.ulong in function argument
Which compiler are you using (5g, 6g, 8g, gccgo)?
CC=clang go build
Which operating system are you using?
ProductName: Mac OS X
ProductVersion: 10.9
BuildVersion: 13A598
Xcode 5.0.1
Build version 5A2034a
Which version are you using? (run 'go version')
go version devel +47b2b07a837f Fri Oct 11 16:39:40 2013 -0700 darwin/amd64
The text was updated successfully, but these errors were encountered:
Error in my original post.
The original problem line was
C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), ksiz)
The fix is:
C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), C.ulong(ksiz))
This seems to be a general problem with the definition of size_t on OS X 10.9. We fixed
it for malloc, but the problem has been reported for calloc and realloc (issue #6506) and
now memcpy. We can't fix each one individually.
by mazdak@chango.com:
The text was updated successfully, but these errors were encountered: