This question, as the subject indicates, is a little confusing so I hope an 
example and code will help (available 
https://gist.github.com/fasiha/29d4639ebd051915ff91 if updates are made):

int print_test(char *name, int use_printf) {
  char out[1024] = {0};
 
  if (use_printf) {
    printf("Hi %s\n", name);
    return 0;
  }
  
  memmove(out, "Yo ", 3);
  memmove(out + 3, name, strlen(name));
  printf("%s", out);
  fflush(stdout);
  return strlen(out);
}



In Chrome and Firefox, making a function handle as `var test = 
Module.cwrap('print_test', 'number', ['string', 'number']);`, when I call 
`print_test` with a string and a 1 (telling it to greet someone using 
printf in the most straightforward way), all is well: I see the output in 
the browser's canvas and JS console.

>> test("z", 01)
Hi z
0

However, if I call this function with 0 for the second argument, and it 
goes to build the string using stack-allocated space and `memmove`, which 
is then printf()'d, no output is seen in the browser.

>> test("z", 0)
4
>> test("zzz", 0)
6


That is, until I call `print_test` with a 1 as the second argument again, 
in which case the outputs of the previous failed attempts appear:

>> test("zzz", 1)
Yo zYo zYo zYo zzzHi zzz
0

As a side-note, when I call `print_test` with 0 second-argument in `main()` 
for Node.js, the outputs are generated as expected---but maybe Node is 
having similar problems as above (in the browser) but it doesn't manifest 
in the command-line.

(I'm trying to troubleshoot some unusual behavior in my actual application, 
which calls `fwrite()` on dynamically-allocated data to print to stdout, 
where sometimes printouts aren't being generated, while other times they 
are, and while there I don't see any queued output, the above is confusing 
enough for me to seek help in understanding Emscripten + browser + printout 
behavior.)

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to