

Using C Dynamic Libraries In Go Programs - gonzo_ed
http://www.goinggo.net/2013/08/using-c-dynamic-libraries-in-go-programs.html

======
AceJohnny2
Coming from a C background, I was pretty disgusted with the "hack" of adding
the include files in a _comment_ before 'import C'. But then, even though they
look similar, Go doesn't treat comments like C does, where they're eliminated
by the C preprocessor and completely invisible to the source.

~~~
james4k
This is because cgo is actually a preprocessor that generates the final C and
Go code that is built. The tools are just good at hiding this. Personally, I
wouldn't say this is a bad thing. You can do some powerful things with this,
including using your own .c and .h files in your Go packages. For a while, the
YAML package at launchpad.net/goyaml did this by using libyaml code directly
instead of having to link to external libraries, though now it is pure Go.

------
jevinskie
I wonder why the author didn't just read() in bytes from STDIN_FILENO? No need
to use stuff like fget*.

~~~
evmar
I think by default your terminal is in "cooked" mode, where stdin is buffered
a line at a time. Try

    
    
      cat /dev/fd/0
    

then type some things including backspace and enter.

However, you don't need ncurses to change this behavior. termios is the lower-
level C API. You can do it from Go with the syscall APIs but I suspect it
might be frustrating to make portable.
[https://code.google.com/p/go/source/browse/ssh/terminal/util...](https://code.google.com/p/go/source/browse/ssh/terminal/util.go?repo=crypto&r=33d6505b6597ddd49a330ed2f8707bcb2c52318c#37)

~~~
zellyn
Yep, it's a bit gnarly. But at least linux/MacOS is straightforward:
[https://groups.google.com/d/msg/golang-
nuts/yRkGpw624-I/htJt...](https://groups.google.com/d/msg/golang-
nuts/yRkGpw624-I/htJtgKNUIZMJ)

------
lcampbell
Another option for this particular example would have been to use pre-existing
ncurses bindings, e.g.,
[https://github.com/tncardoso/gocurses](https://github.com/tncardoso/gocurses)
which somewhat simplifies things.

