I am facing a challenge in passing a double array to a WASM file that is generated through emscripten. I have created it as a .js output file with WASM=1, which also gives me a wasm file.
Below is an excerpt from my C++ code:
#include <iostream>
using namespace std;
extern "C" {
int main(int argc, char** argv) {
return 0;
}
double *calculate(double *x, double *y, int array_length) {
std:cout << "Array Length: " << array_length << endl;
for (int i = 0; i < array_length; i++) {
std::cout << "Coords: " << x[i] << ", " << y[i] << endl;
}
return new double[7]{1,1,2,3,5,8,13};
}
}
The browser console output shows:
Array Length: 4 average.js:8:16057
Coords: 2.36377e+232, 2.36377e+232 average.js:8:16057
Coords: 5.9419e-310, 5.9419e-310 average.js:8:16057
Coords: 4.28375e-319, 4.28375e-319 average.js:8:16057
Coords: 1.4854e-313, 1.4854e-313
Although the code seems to work, I am unsure why the browser output is generated as such. Even when changing the input values in the array, the printed values remain unchanged (except for the quantity). It appears that the c++ code might not be receiving the array properly and instead reading from default allocated memory space. But why?