I tried running this dummy cgo program, it compiles but for some reason when running this obvious program, it doesn't print out anything:
However if I try this more complex program from the wiki, it works and prints the string "Hello from stdio" out normally
package main
/*
#include <stdio.h>
#include <stdlib.h>
void myprint(char* s) {
printf("%s", s);
}
*/
import "C"
import "unsafe"
func main() {
cs := C.CString("Hello from stdio\n")
C.myprint(cs)
C.free(unsafe.Pointer(cs))
}
That's super weird, an obvious program doesn't work, a more complicated one works.
I tried a lot of different ways to figure out why, but so far unable to. Could someone shed some light on why? Could this be a bug or something? It acts as if cgo says "this C code is too simple, let me just omit it.". (I also tried writing the program in C only, compile with gcc and of course it runs as expected).