Helsinki Gophers May 2016 meetup
go build -o demo .
./demo
You can find the presentation at mumakil.fi/p/hki-gophers-may-2016.
You can find the go-libphonenumber project in GitHub at Applifier/go-libphonenumber.
Helsinki Gophers May 2016 meetup
go build -o demo .
./demo
You can find the presentation at mumakil.fi/p/hki-gophers-may-2016.
You can find the go-libphonenumber project in GitHub at Applifier/go-libphonenumber.
| package main | |
| // #import <stdio.h> | |
| // #import <stdlib.h> | |
| import "C" | |
| import "unsafe" | |
| // AllocateAndFree allocates a C string, prints it and frees it | |
| func AllocateAndFree() { | |
| cStr := C.CString("I'm a string, yay!") | |
| defer C.free(unsafe.Pointer(cStr)) | |
| C.puts(cStr) | |
| } |
| #include <stdio.h> | |
| #include "hello_world.h" | |
| void hello_world() { | |
| printf("Hello world!\n"); | |
| } |
| package main | |
| // #include "hello_world.h" | |
| import "C" | |
| // HelloWorld prints out hello world using C code | |
| func HelloWorld() { | |
| C.hello_world() | |
| // Prints "Hello world!" | |
| } |
| void hello_world(); |
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| func main() { | |
| fmt.Println("Example 1: hello world using C") | |
| HelloWorld() | |
| fmt.Println("Example 2: call C namespace") | |
| PrintSquared(8) | |
| fmt.Println("Example 3: allocate and free") | |
| AllocateAndFree() | |
| } |
| package main | |
| // #include <math.h> | |
| import "C" | |
| import "fmt" | |
| // PrintSquared squares the number using C math | |
| func PrintSquared(f float64) { | |
| n, _ := C.pow(C.double(f), C.double(2)) | |
| fmt.Printf("%f squared is %f\n", f, float64(n)) | |
| } |