| |
| Posted by Sean L. Palmer in reply to DeadCow | PermalinkReply |
|
Sean L. Palmer
Posted in reply to DeadCow
| This has been discussed almost to death here in the past.
Anything you're going to want to output to the console you're going to want to be able to also output to a text file, OutputDebugString, a string in memory, etc.
That tells me these things:
* Output should work the same on any stream (drop printf and just have
fprintf, or drop fprintf and make a separate function to designate which
stream is currently being printed to).
* All those things mentioned above are streams or have stream wrappers.
(cout, cin, cerr, file, debug log, string buffer)
But if you always print to strings and then send to stdio, you're wasting performance storing the chars in the string when they really could be stored directly into the stream buffer.
Sean
"DeadCow" <deadcow-remove-this@free.fr> wrote in message news:bfrl3n$g79$1@digitaldaemon.com...
> Im wondering why printf must be a "special case". After all, whatever the argument type is, it will be converted to string. Why dont convert it _before_ call printf ?
>
> What about a printf module with
>
> - a printf functions like:
>
> int printf( char[] format, char[] arg );
> int printf( char[] format, char[] arg1, char[] arg2 );
> int printf( char[] format, char[] arg1, char[] arg2, char[] arg3 );
> int printf( char[] format, char[][] args );
>
> - a set of functions like:
>
> ...
> char[] dec( ... );
> char[] hex( ... );
> char[] oct( ... );
> ...
>
> then we can use printf like this:
>
> int a = 10;
> int b = 5;
> printf( "a=%, b=%\n", hex(a), hex(b) );
>
> ... less elegant but still handy for debuging isn't it ?
>
> For more sofisticated outputs ( padding, ... ), maybe a more specific
class
> can be created.
>
>
|