Xref: utzoo comp.lang.c:17116 comp.unix.wizards:15160 Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!csd4.milw.wisc.edu!leah!rpi!batcomputer!cornell!rochester!pt.cs.cmu.edu!andrew.cmu.edu!bader+ From: bader+@andrew.cmu.edu (Miles Bader) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: How to predict size of outcome of vsprintf? Message-ID: Date: 23 Mar 89 01:55:48 GMT References: <993@etnibsd.UUCP> <9872@smoke.BRL.MIL> <28831@bu-cs.BU.EDU> , <16491@mimsy.UUCP> Organization: Information Technology Center, Carnegie Mellon, Pittsburgh, PA Lines: 30 In-Reply-To: <16491@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: > In article bader+@andrew.cmu.edu > (Miles Bader) writes: > >What I'd really like would be a new function that could act as a basis > >for all the other printf functions, and make it possible to emulate > >them in nice ways. > > > >I would make it a varargs function that takes a bounded output buffer > >and is restartable at the point where it stops due to running into the > >end of the buffer. > > This is fairly difficult to implement (one wants coroutines for something > like this). Instead, why not allow stdio streams to `read' and `write' > via user-provided functions? Everyone knows how to use read() and > write(); simply provide your own write() that mallocs space, or prints > in a window, or whatever. I agree that stdio should have been written with user-provided read/write routines. But I disagree that a restartable sprintf would be difficult. The code needn't be much different at all from a putc based printf (the only difference is that state changes inside the routine are passed out of it). One reason why I like the restartable printf idea is that it's lower overhead and less complex than creating/destroying a stream just for the purpose of implementing sprintf. I just wrote my own stdio-type package; I don't want to have to go though the overhead of passing things through a stdio stream just to get put into MY stream (not that it would be that high; but it's the principle of the thing). -Miles