Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go言語の紹介(かなり浅く浅く)(仮)

HirokiKajiura
August 22, 2014
58

 Go言語の紹介(かなり浅く浅く)(仮)

HirokiKajiura

August 22, 2014
Tweet

Transcript

  1. ࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,

    int b){return (a > b) ? a : b;} ! */ ! ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)); fmt.Println(C.cos(30.0 * 3.14 / 180.0)); } ͜ͷίϝϯτͷதʹ Cݴޠͷιʔε ͜ͷΑ͏ʹҧ࿨ײͳ ͘ݺͼग़ͤΔɽ ϥΠϒϥϦ΋ݺ΂Δ
  2. CݴޠҎ֎Ͱ͸ʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:

    -framework Foundation ! #import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0)NSLog(@"fizzbuzz\n"); else if(i % 5 == 0)NSLog(@"buzz\n"); else if(i % 3 == 0)NSLog(@"fizz\n"); elseNSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) } gccʹೖ͍ͬͯΕ͹ɼCFLAGS͔Β ௚઀ࢦఆͯ͠΍Ε͹೉ͳ͘։͚Δ ϩʔυ͍ͨ͠ϥΠϒϥϦ౳΋ಉ͡ ͘LDFLAGSͰࢦఆग़དྷΔ