"jacob navia" <(E-Mail Removed)> wrote in message
news:lff62i$a0g$(E-Mail Removed)...
> There are several implementations of printf that allow users to define new
> %X formats.
>
> gcc and trio_printf propose a new function like
>
> SetNewPrintfFormat(char format, ...); // arguments are compiler specific
>
> for instance:
> PrintfFlags pf_flags = FLAG_ALTERNATE;
>
> PrintfCallback MyFormattingFunction;
>
> SetNewPrintfFormat('C',MyFormattingFunction);
>
> Then, you can write:
>
> printf("Customer: %C\n",customer);
Would the usual flags and options between % and C also be passed?
If 'customer' was some kind of integer type, would it be necessary to write
the requisite number of "l" width modifiers, or is that expected to be
hard-coded within the spec of the custom function?
> What do you think?
>
> What problems ould be involved with this approach?
Well, one alternative to this, would be:
printf("Customer: %s\n",MyFormattingFunction(customer));
The custom format would keep things shorter if there are lots of 'customer'
types to be printed. Doing it as a standard function returning a string,
also brings up the issue of managing the string memory, but it's not clear
how the custom handler would deal with the same problem.
But on the question of extensions to printf, something that came up in the
'Padding involved' thread was the myriad different formats and modifiers
that are now needed ("%zu" for size_t", or writing "%lld" for long long int
etc).
How hard would it be to implement something like "%?", where ? is
substituted with an appropriate default format matching each argument? (Or
perhaps %?d where ? is the requisite number of "l" modifers needed.)
--
Bartc
news:lff62i$a0g$(E-Mail Removed)...
> There are several implementations of printf that allow users to define new
> %X formats.
>
> gcc and trio_printf propose a new function like
>
> SetNewPrintfFormat(char format, ...); // arguments are compiler specific
>
> for instance:
> PrintfFlags pf_flags = FLAG_ALTERNATE;
>
> PrintfCallback MyFormattingFunction;
>
> SetNewPrintfFormat('C',MyFormattingFunction);
>
> Then, you can write:
>
> printf("Customer: %C\n",customer);
Would the usual flags and options between % and C also be passed?
If 'customer' was some kind of integer type, would it be necessary to write
the requisite number of "l" width modifiers, or is that expected to be
hard-coded within the spec of the custom function?
> What do you think?
>
> What problems ould be involved with this approach?
Well, one alternative to this, would be:
printf("Customer: %s\n",MyFormattingFunction(customer));
The custom format would keep things shorter if there are lots of 'customer'
types to be printed. Doing it as a standard function returning a string,
also brings up the issue of managing the string memory, but it's not clear
how the custom handler would deal with the same problem.
But on the question of extensions to printf, something that came up in the
'Padding involved' thread was the myriad different formats and modifiers
that are now needed ("%zu" for size_t", or writing "%lld" for long long int
etc).
How hard would it be to implement something like "%?", where ? is
substituted with an appropriate default format matching each argument? (Or
perhaps %?d where ? is the requisite number of "l" modifers needed.)
--
Bartc
Aucun commentaire:
Enregistrer un commentaire