Last active
August 29, 2015 14:13
-
-
Save minoki/d0899350c852b2d154f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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; | |
} |
This file contains hidden or 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
#![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