James Buchanan wrote:
Waldek Hebisch wrote:
Variable parameters (Pascal term) are quite different than varargs (C term). For compatibility with C GPC supports calling varargs functions. GPC does not support writing varargs functions (you can write a trivial one, but there is no way to get the parameters). Note that Writeln is _not_ a varargs function. Writeln is converted by the compiler into calls for separate arguments -- no user defined function can behave the same as Writeln.
Oh well, it's not as if it's absolutely essential. It's not a great hassle to have to break up the output into separate calls. Less than elegant, but not too bad.
In Pascal you might prefer not to rewrite the "print"/"write" function (which is common practice in C, such as "printk"), but to use the existing Write[Ln] and redirect its output. This way, you leave the breaking up of the output and the formatting ("i : 42" etc.) to the compiler as usual, and basically only need to provide routines to output a raw sequence of characters (cf. roughly snprintf() / write() in C).
For this purpose, GPC supports "text file device drivers" (look for "AssignTFDD" in gpc.pas). Of course, you'll need to use some parts of the GPC RTS (or equivalent subsitutes) for it to work.
Then you can assign a "Text" file to your output routine and do a normal "WriteLn (MyFile, whatever)". In fact you can even assign "Output" and do just "WriteLn (whatever)", if you don't need "Output" otherwise.
Then again I could call a C function that does it, so the I/O routines are written in C rather than Pascal. I'll try both and then think on it before putting anything in.
Since GPC allows calling varargs, that's an option. Just be careful of integer sizes etc. (e.g., integer expressions may be of type LongInt unexpectedly).
Frank