Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Request comments - printx |
| Date | 2016-10-16 23:44 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <nu0vsd$vjo$1@dont-email.me> (permalink) |
| References | <kfnh98e7nxs.fsf@x-alumni2.alumni.caltech.edu> |
On 14/10/2016 20:03, Tim Rentsch wrote:
> I am soliciting comments and suggestions for a small family of
> functions (and a few supporting macro and type definitions) which
> I have taken to calling "printx", with printx() being the
> representative function of the family.
> printx( "The value of z is %!\n", Fcomplex, z );
> _Complex float zf = z;
> _Complex long double zld = z;
>
> printx( "zf is %h!, zld is %L!\n", _Fcomplex, zf, _Fcomplex, zld );
> printx( "z with 3 decimal places: %.3!\n", Fcomplex, z );
>
> which gives
>
> z with 3 decimal places: (1.230 + 4.560*I)
>
> or an argument value precision specifier:
>
> printx( "z with 2 decimal places: %.*!\n", 2, Fcomplex, z );
>
> which gives
>
> z with 2 decimal places: (1.23 + 4.56*I)
> int m[4][3] = {
> { 1, 2, 3 },
> { 2, 3, 4 },
> { 3, 4, 5 },
> { 4, 5, 6 },
> };
> printx( " m = %!;\n", Fmatrix, 4, 3, " ", m, " " );
>
> which produces:
>
> m = {
> { 1, 2, 3, },
> { 2, 3, 4, },
> { 3, 4, 5, },
> { 4, 5, 6, },
> };
No real comments but just a summary of how I believe your extension works:
* printx-family functions can be plug-in replacements for printf-family
* printx recognises a new "%...!" format code
* When "%..!" is seen, that takes a special operand off the list of
arguments that is being scanned, that needs to be a custom formatter
(function?) like _Fcomplex (after any * arguments if necessary).
* The custom formatter then takes over popping and using as many more
arguments as it needs, before finishing. The format is now positioned
just after the "!" and the process continues.
* Any standard format codes are presumably passed on to regular printf
functions or otherwise processed as normal.
* printx functions can be recursive (the handler for one format may make
use of further printf calls)
* Multiple "%..!" codes can occur in a single format string
interspersed with normal format codes.
A couple of issues that I can see: with regular printf, the compiler can
warn against mismatches between format code and argument type, which I
don't think would be possible here.
Also, especially with examples such as Fmatrix, it is easy to miss out
an argument or add an extraneous one. What happens if the next "!"
expects something like an _Fcomplex but it gets an integer instead?
(This happens with normal printf too but that doesn't usually end up
calling an argument, if that is what happens with printx. And some
compilers can check the number and type of printf arguments as I said.)
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-14 12:03 -0700
Re: Request comments - printx supercat@casperkitty.com - 2016-10-14 13:06 -0700
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-15 15:28 -0700
Re: Request comments - printx supercat@casperkitty.com - 2016-10-17 10:26 -0700
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-18 08:42 -0700
Re: Request comments - printx supercat@casperkitty.com - 2016-10-20 09:12 -0700
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-22 19:23 -0700
Re: Request comments - printx Ian Collins <ian-news@hotmail.com> - 2016-10-16 17:30 +1300
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-16 00:22 -0700
Re: Request comments - printx Ian Collins <ian-news@hotmail.com> - 2016-10-16 20:37 +1300
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-17 11:22 -0700
Re: Request comments - printx BartC <bc@freeuk.com> - 2016-10-16 23:44 +0100
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-17 10:29 -0700
Re: Request comments - printx BartC <bc@freeuk.com> - 2016-10-17 18:57 +0100
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-18 08:20 -0700
Re: Request comments - printx Nick Bowler <nbowler@draconx.ca> - 2016-10-19 17:10 +0000
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-20 08:58 -0700
Re: Request comments - printx raltbos@xs4all.nl (Richard Bos) - 2016-10-23 13:37 +0000
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-23 14:16 -0700
Re: Request comments - printx Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-10-18 02:41 -0700
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-18 08:37 -0700
Re: Request comments - printx Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-10-18 08:45 -0700
Re: Request comments - printx Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-10-18 09:46 -0700
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-18 23:33 -0700
Request comments - printx asetofsymbols@gmail.com - 2016-10-23 00:39 -0700
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-23 14:08 -0700
Re: Request comments - printx Richard Heathfield <rjh@cpax.org.uk> - 2016-11-09 16:32 +0000
Re: Request comments - printx "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-10 01:03 +0800
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-11-12 17:53 -0800
Re: Request comments - printx Richard Heathfield <rjh@cpax.org.uk> - 2016-11-13 16:43 +0000
Re: Request comments - printx Tim Rentsch <txr@alumni.caltech.edu> - 2016-11-15 10:37 -0800
csiph-web