[Challenge] implementing the ambiguous operator in D
Denis Koroskin
2korden at gmail.com
Sun Sep 5 09:30:03 PDT 2010
On Sun, 05 Sep 2010 20:18:13 +0400, bearophile <bearophileHUGS at lycos.com>
wrote:
> Denis Koroskin:
>> Turn main into an "extern(C) int main()" and it works.
>
> This version:
>
> import std.c.stdio: puts;
>
> version (Windows) {
> alias int[16] jmp_buf;
> extern (C) extern {
> int setjmp(ref jmp_buf env);
> void longjmp(ref jmp_buf env, int value);
> }
> }
>
> struct State {
> int save() {
> return setjmp(buf);
> }
>
> void restore(int status) {
> assert(status != 0);
> longjmp(buf, status);
> }
>
> private jmp_buf buf;
> }
>
> extern(C) int main() {
> State state;
> int result = state.save();
> if (result == 0) {
> // first time here
> puts("state saved");
> state.restore(1);
> } else {
> assert(result == 1);
> puts("state restored");
> }
> return 0;
> }
>
>
> Gives link errors:
> test.obj(test)
> Error 42: Symbol Undefined __d_assertm
> test.obj(test)
> Error 42: Symbol Undefined __d_assert_msg
>
> Bye,
> bearophile
Try linking with phobos explicitly:
# dmd test.d phobos.lib
More information about the Digitalmars-d
mailing list