Prof A Olowofoyeku (The African Chief) wrote:
It is the libplot library itself that wants to write to these file pointers. It turns out that was I needed was a way to pass to the libplot routines pointers to the actual libc "stdin", "stdout" and "stderr", as opposed to Pascal implementations. I achieved it by writing a small C wrapper ("plotc.c"), with these:
#include <stdio.h> FILE *libc_stdin (void); FILE *libc_stdin (void) {return stdin;}
FILE *libc_stdout (void); FILE *libc_stdout (void) {return stdout;}
FILE *libc_stderr (void); FILE *libc_stderr (void) {return stderr;}
Then in the Pascal unit, I have "{$L plotc.c}", and then I declare these: Type TPlotFile = Pointer; Function libc_stdin : TPlotFile; external name 'libc_stdin'; Function libc_stdout : TPlotFile; external name 'libc_stdout'; Function libc_stderr : TPlotFile; external name 'libc_stderr';
So in the calling program I can pass the libc_std* to libplot routines, and everyone seems happy ...
It probably makes more sense to use external variables than external functions, but trying to make the libc_std* stuff into variables caused GPFs. I am not too bothered to try to sort it out, as the functions work perfectly well.
Indeed, stdin etc. are not plain variables on many systems (they can be array references or pointer indirections via macros).
So functions returning them seems the only portable way to get them, and what you wrote is exactly what I'd have suggested.
Frank