Default Stream

However, while the old Prolog I/O system is based on the C standard I/O library, the new Prolog I/O system is not. If an application performs mixed I/O operation in Prolog and foreign code on the three default Prolog streams, it might not work appropriately under the new I/O due to incompatibilities between the buffering mechanism in the C standard I/O stream and the Quintus Prolog stream.

Let's look at an example of a mixed output operation on a Prolog session under UNIX. Both the C standard output stream and the Prolog user_output stream write output to the same file descriptor, 1, which is a tty.

     | ?- set_output(user_output), write(first), c_printf('FIRST'),
          write(second), c_printf('SECOND'), nl, c_nl.

The predicate c_printf/1 and c_nl/0 calls the following C functions:

     void c_printf(atom)
          char *atom;
          {    printf("%s", atom); }
     void c_nl() { putchar('\n'); }

The query yields the following output as expected prior to Quintus Prolog release 3.


However it yields the following output on Quintus Prolog release 3 since each stream has its own buffer and no characters are actually written to the file descriptor 1 until new line operation is called.


This problem can be solved by supplying a different embedding QU_initio() function at the time of the installation of Quintus Prolog (or at the time of creating a statically linked Prolog system) to create the three default streams based on C standard I/O streams. How to create an unbuffered Prolog stream based on a C standard I/O stream has already been shown in the third example of creating customized Prolog streams (see fli-ios-uds-sst)