Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch2.7.2 C临时访问传入的Go内存 P111的示例没有打印输出 #511

Open
dev-go opened this issue May 15, 2020 · 2 comments
Open
Assignees

Comments

@dev-go
Copy link

dev-go commented May 15, 2020

ch2.7.2 C临时访问传入的Go内存 P111的示例没有打印输出

Screenshot from 2020-05-15 23-01-21

@dev-go
Copy link
Author

dev-go commented May 16, 2020

修改为如下代码就可以正常输出了, 难道是线程退出时没有刷新缓冲区??????
package main

/*
void printString(const char* s) {
	printf("%s", s);
        printf("\n");
}
*/
import "C"

func printString(s string) {
	cs := C.CString(s)
	defer C.free(unsafe.Pointer(cs))

	C.printString(cs)
}

func main() {
	s := "hello"
	printString(s)
}

@chai2010
Copy link
Owner

可以手工调用 fflush( stdout );试试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants