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
What does 'go version' print?
go version go1.3.1 linux/amd64
What steps reproduce the problem?
Take the first example on this page:
https://code.google.com/p/go-wiki/wiki/cgo
Add
func main() { Example() }
remove "\n" from cs
build and run
What happened?
Nothing prints
What should have happened instead?
it should have printed "Hello from stdio" without a trailing newline
Additional detail:
If "\n" appears in the printf argument anywhere, it will print till \n and
discard everything after \n
ex:
if you change cs to "Hello from stdio \n and go ", it will print
"Hello from stdio"
this will happen even if you modify printf directly
ex:
if printf is modified to
printf("%s 123 ", s);
it will print till the last "\n" it encounters and discard the rest. so if s
was "hello from stdio\n", it will print "hello from stdio" and
discard 123
If possible, include a link to a program on play.golang.org.
import "C" wont work on play.golang.org
The text was updated successfully, but these errors were encountered:
The problem is that returning from the C main function flushes the C streams, as does
calling the C exit function. Returning from the Go main function, or calling os.Exit,
does not flush the C streams. By default C's standard output flushes on newline. That
is why you see the behaviour that you do.
I'm not sure whether to consider this a bug in Go or not. You can work around it by
explicitly calling C.fflush(nil) before main returns.
if Go is the primary frontend for compiling mixed code, I would categorize it as an
issue in Go. Esp. since Go is separating the codes and compiling them, it might be a
good idea to implicitly mimic C stream flush behavior.
This can be very confusing for new users and a potential headache for large codebases
using mixed languages. Either this needs to be explicitly documented and well publicized
or it should be taken care of implicitly.
by kalyanakrishna:
The text was updated successfully, but these errors were encountered: