Hacker News new | ask | show | jobs
by moefh 1528 days ago
This is really cool! I never looked into WASM before, I'm really happy to see it's not that difficult to build a simple example like this.

One thing that's bothering me about that code is the declaration of `memory` as an uint8_t when it's clearly being used for its address:

    extern uint8_t memory;
And then in a lot of places:

    uint8_t* ptr = &memory;
    ptr[FOO] = BAR;
Declaring `memory` as an array is much more idiomatic C, and generates the exact same assembly:

    extern uint8_t memory[];
And then

    memory[FOO] = BAR;
I just tested it, and it seems to work exactly as one would expect from a plain C linker (so there's no WASM magic I can see). Am I missing something?
1 comments

Pedantically, it might even be undefined behaviour (not sure, maybe a point of contention, similar to container_of macro). It's unlikely to cause problems, but the way you suggested is better (and can even be accompanied by a length field).

Thank you to the author though! It is a nice little example.