D - printf issue
- DeadCow (22/22) Jul 25 2003 Im wondering why printf must be a "special case". After all, whatever th...
- Sean L. Palmer (17/39) Jul 25 2003 This has been discussed almost to death here in the past.
- Walter (4/7) Jul 30 2003 stored
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.
Jul 25 2003
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 specificclasscan be created.
Jul 25 2003
"Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bfrnoh$imv$1 digitaldaemon.com...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 bestoreddirectly into the stream buffer.Yup. The key to fast I/O is avoiding extra copies.
Jul 30 2003