Using the full range of uint64_t across the language boundary

28 views
Skip to first unread message

Márton Marczell

unread,
Oct 20, 2021, 5:49:36 AM10/20/21
to emscripten-discuss
Hi,

Given this example code:

#include <iostream>
#include <emscripten.h>

#define MYINT64 uint64_t

extern "C" void EMSCRIPTEN_KEEPALIVE bar (MYINT64 n) {
    std::cout << "C++ called from JS: " << n << std::endl;
}

EM_JS(void, foo, (MYINT64 i), {
    console.log("JS", i, typeof(i));

    Module.ccall('bar', null, ['number'], [i]);
});

int main() {
    auto some = std::numeric_limits<MYINT64>::max();
    std::cout << "C++ " << some << std::endl;
    foo(some);
}

The code prints:

C++ 18446744073709551615
JS -1n bigint
C++ called from JS: 18446744073709551615

Márton Marczell

unread,
Oct 20, 2021, 5:50:19 AM10/20/21
to emscripten-discuss
Why does the number become negative in JS and what would be required for this to work?

I did compile with -sWASM_BIGINT.


Reply all
Reply to author
Forward
0 new messages