-----Message d'origine----- De : gpc-owner@gnu.de [mailto:gpc-owner@gnu.de] De la part de Frank Heckenbach Envoyé : March 15, 2006 05:33 À : gpc@gnu.de Objet : Re: RE : RE : Variable number of parameters
Pascal Viandier wrote:
FormatString should be able to do it. It doesn't yet as the current implementation is not much more than a stub (it was done in a hurry ;-).
Is there an example of what FormatString can do already and how to call it? The FormatString entry in the documentation is almost empty and there is no
demo
program for it.
Not yet (as I said, done in a hurry), only a few test programs, in particular fjf629[efg].pas. But when you understood it, feel free to send us some. :-)
I tried it but found only that the character '%' followed by any letter is used as a place holder for remaining parameters and the letter is
not
used.
Yes, because GPC has type information itself already, i.e. it's not necessary to distinguish between %s for strings and %i for numbers.
BTW, this part of FormatString is implemented in Pascal (InternalFormatString in p/rts/string2.pas), so perhaps someone who doesn't like C programming might want to help here ...
Reading the source code did not help much. What is the character '@' used
for in
the format string?
To specify a different argument to write. E.g. %@2s will output the 2nd parameter, instead of the next one. This is sometimes needed in i18n.
BTW, I see that glibc added a different syntax for the same purpose, apparently later than we did, namely %2$s. Perhaps we should consider changing it (e.g., to make things easier for i18n translators), if the %@2s syntax isn't in widespread use yet.
That basically all it does now. As I wrote, it doesn't have padding options yet, though space-padding and precision of reals can be given as in Write statements, e.g. FormatString ('%s', Pi : 10 : 5). (But we should add at least space- and zero padding facilities in the format string, indeed.)
What do you think about the idea of calling sprintf() from InternalFormatString after appropriate transformation of the format string and adaptation of the parameters?
After all, both have almost the same purpose with the advantage for sprintf for the formatting we would like to add to InternalFormatString.
I think the challenging part - for me - would be to pass the arguments to sprintf() since I do not understand yet how the parameters passing mechanism works.
You (Frank) wrote previously that one cannot make a Pascal function accepting a variable number of parameters. At my surprise FormatString is exactly that.
Am I right, somewhat right or wrong? Did I miss something?
Regards
Pascal