[GRASS5] Problem compiling Grass51

Glynn Clements glynn.clements at virgin.net
Wed May 21 15:32:04 EDT 2003


Paul Kelly wrote:

> > > I have added Eric's G_asprintf to 5.1 now as I tested it a bit and it
> > > seemed to work best for me. So now it can get a bit more testing. I didn't
> > > realise before but it needs to be used like:
> > >
> > > 	char *str;
> > > 	G_asprintf( &str, "format etc..%s", otherstring);
> >
> > Is there any reason why it can't be changed to:
> >
> > 	str = G_asprintf("format etc..%s", otherstring);
> >
> > ?
> 
> That is maybe better, more like G_store() (whose functionality is quite
> similar). Maybe it could be called G_storef() then.

I think that G_asprintf() is the right name.

> Whatever you think. Is
> the main reason for changing it that it's confusing the way it is?

It just seems more natural. OTOH, the existing prototype matches
asprintf(), so maybe it should be kept.

> I had
> never seen that way of passing a pointer to a pointer before but it seems
> to work?

It will certainly work; the only difference is stylistic.

Maybe that interface was chosen to mimic fprintf, sprintf etc, which
take the "destination" as the first argument. Or maybe it was to force
the caller to store the result somewhere, to prevent memory leaks from
doing this sort of thing:

	foo(..., asprintf(fmt, ...), ...);

Originally I just thought that returning the pointer was neater, but I
can see arguments for the existing interface.

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-dev mailing list