Re: [PATCH 1/2] Add strbuf_initf()
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Mar 6, 2008, 10:53 UTC
- Message-ID
- <alpine.LSU.1.00.0803061148180.15786@racer.site>
- In-Reply-To
- <20080306063331.GA7325@glandium.org>
Hi,
On Thu, 6 Mar 2008, Mike Hommey wrote:
Show 13 quoted lines
> On Thu, Mar 06, 2008 at 02:14:43AM +0100, Johannes Schindelin wrote: > > > > The most common use of addf() was to init a strbuf and addf() right > > away. Since it is so common, it makes sense to have a function > > strbuf_initf() to wrap both calls into one. > > > > Unfortunately, C (and cpp) has no way to make this easy without code > > duplication, as we need to va_init() in strbuf_addf() possibly a few > > times. So the code for addf() is copied. Fortunately, the code is > > pretty short, so not too much had to be copied as-is. > > The problem with code duplication is not about code size, but more about > not forgetting to fix bugs in all incarnations of the duplicated code.
Yes, I know.
> Is it so ugly to use a macro ?
AFAIR it is unportable to have a macro
#define strbuf_initf(buf, fmt, ...) \ (strbuf_init(buf, strlen(fmt) + 64), strbuf_addf(buf, fmt, args);)
(GNU cpp groks it, but what about the others?)
Or you mean the whole body of the implementation of strbuf_addf()? Now, _that_ would be ugly.
Ciao, Dscho