Skip to content

Instantly share code, notes, and snippets.

@minoki
Last active August 29, 2015 14:13
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 minoki/d0899350c852b2d154f0 to your computer and use it in GitHub Desktop.
Save minoki/d0899350c852b2d154f0 to your computer and use it in GitHub Desktop.
#include <cstdio>
class Foo
{
int x;
public:
Foo(int x);
~Foo();
void greet();
};
Foo::Foo(int x) : x(x)
{
}
Foo::~Foo()
{
}
void Foo::greet()
{
std::printf("Hello world! x=%d\n", x);
}
Foo *newFoo(int x)
{
return new Foo(x);
}
void deleteFoo(Foo *p)
{
delete p;
}
#![feature(link_args)]
extern crate libc;
use libc::types::os::arch::c95::{c_int};
enum Foo {}
#[link_args = "foo.o"]
extern {
fn _Z6newFooi(x: c_int) -> *mut Foo;
fn _Z9deleteFooP3Foo(p: *mut Foo);
fn _ZN3Foo5greetEv(this: *mut Foo);
}
fn main() {
unsafe {
let foo = _Z6newFooi(42);
_ZN3Foo5greetEv(foo);
_Z9deleteFooP3Foo(foo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment