dont understand cgo. printf doesnt print a thing?

163 views
Skip to first unread message

sperber...@googlemail.com

unread,
Jan 25, 2015, 3:54:41 AM1/25/15
to golan...@googlegroups.com
Hi folks,

i have the following code:
package main

/*
#include <stdio.h>
#include <stdlib.h>

int myinit(int x) {
        printf("%s hello","test");
        return x;
}
*/
import "C"

import "fmt"

func main() {
        x := C.myinit(3)
        fmt.Println(x)
}

if i do a go build and run it the output is the following:
$ ./main
3

why is nothing printed? can someone explain what i am doing wrong?
It doesnt matter if i use go1.4 or go1.5+devel

yours

Dmitry Vyukov

unread,
Jan 25, 2015, 10:45:38 PM1/25/15
to sperber...@googlemail.com, golang-nuts
Try to add \n at the end of the string, or call fflush(stdout);
Reply all
Reply to author
Forward
0 new messages