fflush(stdout) does not work.

12 views
Skip to first unread message

Thomas Mertes

unread,
Jun 1, 2019, 8:07:45 AM6/1/19
to emscripten-discuss
Hello,

I have a small test program that shows:
flush(stdout) is not working!
---------- begin tst249.c ----------
#include "stdio.h"
#include "unistd.h"

int main (int argc, char *argv[])
  {
    printf("start\nxxx\r");
    fflush(stdout);
    sleep(1);
    printf("end\n");
    return 0;
  }
---------- end tst249.c ----------

This program should write:

  start
  xxx

then it should wait for a second and overwrite "xxx" with "end":

  start
  end

So for one second you should see the "xxx".
When compiling with gcc or clang it just works this way.
I compile tst249.c with emcc:

  myPrompt> emcc tst249.c -o tst249.js

When I execute tst249.js with node.js it writes:

  start

then it waits for a second and writes "end":

  start
  end

Probably "xxx" is written and immediately overwritten with "end".
The flush(stdout) just does not flush the "xxx".

I think that writing '\n' triggers a flush, but fflush() does not.
So somewhere code to flush exists already (since it is used for '\n'),
but this code to flush is just not called, when fflush(stdout) is
invoked.

Regards,
Thomas Mertes

--
Seed7 Homepage:  http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.

Reply all
Reply to author
Forward
0 new messages