-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
69 additions
and
453 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <gc_cpp.h> | ||
|
||
struct Person { | ||
char* name; | ||
int age; | ||
Person* people; | ||
}; | ||
|
||
Person createPerson(const char* name, int age) { | ||
Person p; | ||
p.name = GC_strdup(name); | ||
p.age = age; | ||
p.people = static_cast<Person*>(GC_malloc(sizeof(Person))); | ||
// FIXME: undefined reference to `__gxx_personality_v0' | ||
// p.people = gc_allocator<Person>().allocate(1); | ||
return p; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import bdwgc; | ||
|
||
extern (C++) | ||
{ | ||
struct Person | ||
{ | ||
char* name; | ||
int age; | ||
Person* people; | ||
} | ||
|
||
Person createPerson(const(char)* name, int age); | ||
} | ||
extern (C): | ||
void main() | ||
{ | ||
GC_init(); | ||
GC_set_all_interior_pointers(1); | ||
|
||
Person p1 = createPerson("John", 42); | ||
Person p2 = createPerson("Sarah", 35); | ||
GC_gcollect(); | ||
GC_printf("%s, have %d years old.\n", p1.name, p1.age); | ||
GC_printf("%s, have %d years old.\n", p2.name, p2.age); | ||
} | ||
pragma(printf) | ||
void GC_printf(const(char)* format, ...); |
Oops, something went wrong.