I have a simple C function that modifies elements of an integer array. I can convert it to JavaScript using Emscripten (emcc) without problems. But when I call the function on a JS array, the values in it do not seem to change. Please help.
This is the C function definition:
/* modify_array.c */
void modify_array(int X[8]) {
int i;
for (i = 0; i < 8; ++i) {
X[i] += 1;
}
}
This is the command I used to transpile the C code to JS:
emcc modify_array.c -o modify_array.js -s EXPORTED_FUNCTIONS="['_modify_array']"
And this is the JavaScript (Node.js) code for invoking the transpiled JS code:
var mod = require("./modify_array.js");
var f = mod.cwrap("modify_array", "undefined", ["array"]);
var X = [0, 1, 2, 3, 4, 5, 6, 7];
var bytesX = new Uint8Array(new Int32Array(X).buffer);
/* Invoke the emscripten-transpiled function */
f(bytesX);
console.log(new Int32Array(bytesX.buffer));
After running the JS code, the buffer contains values that are identical to the original values, not the incremented values. Why? How can I get the updated values?