Created
March 27, 2017 21:39
-
-
Save elorest/76831e95c5c14a72df6407a152a20916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@[Link(ldflags: "#{__DIR__}/say.o")] | |
@[Link("m")] | |
lib LibSay | |
struct Person | |
name : UInt8* | |
height : UInt8* | |
age : Int32 | |
end | |
fun hello_ptr(p : LibSay::Person*) : Void | |
fun hello(p : LibSay::Person) : Void | |
end | |
p = LibSay::Person.new(name: "Isaac", age: 33, height: "5'11\"") | |
LibSay.hello_ptr(pointerof(p)) | |
LibSay.hello(p) | |
lib LibMath | |
fun pow(x : Float64, y : Float64) : Float64 | |
end | |
puts LibMath.pow(2,3).to_i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
typedef struct { | |
char * name; | |
char * height; | |
int age; | |
} Person; | |
void hello_ptr(const Person * p){ | |
printf("Hello %s! Are you really %d and only %s tall?\n", p->name, p->age, p->height); | |
} | |
void hello(Person p){ | |
printf("Hello %s! Are you really %d and only %s tall?\n", p.name, p.age, p.height); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gcc -c say.c && crystal build helloworld.cr