Skip to content

Instantly share code, notes, and snippets.

@elorest
Created March 27, 2017 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elorest/76831e95c5c14a72df6407a152a20916 to your computer and use it in GitHub Desktop.
Save elorest/76831e95c5c14a72df6407a152a20916 to your computer and use it in GitHub Desktop.
@[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
#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);
}
@elorest
Copy link
Author

elorest commented May 11, 2017

gcc -c say.c && crystal build helloworld.cr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment