[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: data_out

From: Ben Pfaff
Subject: Re: data_out
Date: Thu, 27 Apr 2006 22:31:30 -0700
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

John Darrington <address@hidden> writes:

> On Thu, Apr 27, 2006 at 09:32:52PM -0700, Ben Pfaff wrote:
>      John Darrington <address@hidden> writes:
>      > Any objections if  we change the signature of data_out, so that the
>      > first argument is char ** or struct string * , and have the function
>      > allocate the required amount of storage?
>      >
>      >
>      > Right now, we never know how big a string needs to be passed to it.
>      We don't?  The string has to be as wide as the field width, fp->w.
> I stand corrected.  We do know, but it's non constant. It might be 1
> on the first call and 10000 the next.

Well, it's a little more constrained than that.  Numeric field
widths are never over 40.  String field widths are never over

> Perhaps I should explain my motives. I want to append the
> result to a struct string.  The only way I can currently do
> that is to violate the encapsulation of struct string.
>      {
>        struct string s;
>        ds_init(&s);
>        .
>        .
>        .
>        x = ds_length(&s);
>        /* Somehow make sure that s has sufficient length */
>        data_out (ds_c_str(&s)+x, &v->print, case_data (c, v->fv));
>      }                                          

It seems to me that this really just calls for a new string
function that allocates space without initializing it.  You could
call it ds_append_uninitialized() and make it take the number of
bytes to append and return a pointer to the space.  Then your
call to data_out would look like this:
        data_out (ds_append_uninitialized (&s, v->print.w),
                  &v->print, case_data (v, v->fv));
Of course, you could break the call to ds_append_uninitialized()
into a separate statement if that looks too obscure.

I don't know whether "ds_append_uninitialized" is a good name.
Ben Pfaff 
email: address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]