www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.stream.vprintf

reply ben <ben_member pathlink.com> writes:
How can I make use of std.stream.vprintf.  This if obviously wrong, because it
won't compile.

import std.stream;
import std.c.process;

void die(char[] fmt, ...){
std.stream.vprintf(fmt, _argptr);
exit(1);
}

Any help is much appreciated.  
Jun 13 2005
next sibling parent reply Derek Parnell <derek psych.ward> writes:
On Tue, 14 Jun 2005 05:20:46 +0000 (UTC), ben wrote:

 How can I make use of std.stream.vprintf.  This if obviously wrong, because it
 won't compile.
 
 import std.stream;
 import std.c.process;
 
 void die(char[] fmt, ...){
 std.stream.vprintf(fmt, _argptr);
 exit(1);
 }
 
 Any help is much appreciated.

import std.stdarg; void die(char[] fmt, ...) { va_list ap; ap = cast(va_list) &fmt; ap += fmt.sizeof; std.stream.vprintf(fmt, ap); } -- Derek Melbourne, Australia 14/06/2005 3:29:15 PM
Jun 13 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Tue, 14 Jun 2005 15:31:34 +1000, Derek Parnell wrote:

 On Tue, 14 Jun 2005 05:20:46 +0000 (UTC), ben wrote:
 
 How can I make use of std.stream.vprintf.  This if obviously wrong, because it
 won't compile.
 
 import std.stream;
 import std.c.process;
 
 void die(char[] fmt, ...){
 std.stream.vprintf(fmt, _argptr);
 exit(1);
 }
 
 Any help is much appreciated.

import std.stdarg; void die(char[] fmt, ...) { va_list ap; ap = cast(va_list) &fmt; ap += fmt.sizeof; std.stream.vprintf(fmt, ap); }

Nope, this doesn't work either. Sorry, but maybe its a lead. -- Derek Melbourne, Australia 14/06/2005 3:47:05 PM
Jun 13 2005
parent Derek Parnell <derek psych.ward> writes:
On Tue, 14 Jun 2005 15:47:48 +1000, Derek Parnell wrote:

 On Tue, 14 Jun 2005 15:31:34 +1000, Derek Parnell wrote:
 
 On Tue, 14 Jun 2005 05:20:46 +0000 (UTC), ben wrote:
 
 How can I make use of std.stream.vprintf.  This if obviously wrong, because it
 won't compile.
 
 import std.stream;
 import std.c.process;
 
 void die(char[] fmt, ...){
 std.stream.vprintf(fmt, _argptr);
 exit(1);
 }
 
 Any help is much appreciated.

import std.stdarg; void die(char[] fmt, ...) { va_list ap; ap = cast(va_list) &fmt; ap += fmt.sizeof; std.stream.vprintf(fmt, ap); }

Nope, this doesn't work either. Sorry, but maybe its a lead.

Here is one that does work ... <code> import std.stdarg; import std.stream; BufferedFile f; void die(char[] fmt, ...) { va_list ap; ap = cast(va_list) &fmt; ap += fmt.sizeof; f.vprintf(fmt, ap); } void main() { f = new BufferedFile("c:\\temp\\test.txt", FileMode.OutNew); // NOTE **** The usage of 'C' style string format code '%.*s' die("Code: %d is '%.*s'\n", 12, "test value"); f.close(); } </code> -- Derek Melbourne, Australia 14/06/2005 4:04:58 PM
Jun 13 2005
prev sibling next sibling parent reply Vathix <vathix dprogramming.com> writes:
On Tue, 14 Jun 2005 01:20:46 -0400, ben <ben_member pathlink.com> wrote:

 How can I make use of std.stream.vprintf.  This if obviously wrong,  
 because it
 won't compile.

 import std.stream;
 import std.c.process;

 void die(char[] fmt, ...){
 std.stream.vprintf(fmt, _argptr);
 exit(1);
 }

 Any help is much appreciated.

Not an answer but it would be nice if there was vwritef(). While looking through the docs I noticed writef() returns Stream when it should probably return OutputStream.
Jun 13 2005
parent Derek Parnell <derek psych.ward> writes:
On Tue, 14 Jun 2005 02:25:23 -0400, Vathix wrote:

 On Tue, 14 Jun 2005 01:20:46 -0400, ben <ben_member pathlink.com> wrote:
 
 How can I make use of std.stream.vprintf.  This if obviously wrong,  
 because it
 won't compile.

 import std.stream;
 import std.c.process;

 void die(char[] fmt, ...){
 std.stream.vprintf(fmt, _argptr);
 exit(1);
 }

 Any help is much appreciated.

Not an answer but it would be nice if there was vwritef().

Yes, I was just thinking the same thing. And I just slapped myself because a simpler solution is just ... BufferedFile f; void die(char[] fmt, ...) { f.vprintf(fmt, _argptr); } -- Derek Melbourne, Australia 14/06/2005 4:28:26 PM
Jun 13 2005
prev sibling parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
"ben" <ben_member pathlink.com> wrote in message 
news:d8lpfe$6ho$1 digitaldaemon.com...
 How can I make use of std.stream.vprintf.  This if obviously wrong, 
 because it
 won't compile.

 import std.stream;
 import std.c.process;

 void die(char[] fmt, ...){
 std.stream.vprintf(fmt, _argptr);
 exit(1);
 }

 Any help is much appreciated.

note vprintf is not static so one must supply an instance of a stream as Derek's post suggests.
Jun 29 2005