best way to return (char *)

steve emmerson steve at umigw.MIAMI.EDU
Fri Jun 23 22:45:04 AEST 1989


In article <18234 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>  This question does not have a single best answer;
>there is not sufficient information here to choose one.

Chris is right: without some criteria, it is difficult to choose one
method over another.

I believe you did, however, mention a safety criterion.  In that case,
the _safest_ method is probably to allocate the memory in the called
routine as you can be certain of valid storage.  As someone pointed out,
however, this can lead to allocation and deallocation calls at
different levels.  It can also lead to clutter, if you forget to
deallocate.

A close second in safety, and one which reminds the user to deallocate,
is to have the caller instantiate the buffer.

Both these methods have wide usage.  It's your call.
-- 
Steve Emmerson                     Inet: steve at umigw.miami.edu [128.116.10.1]
SPAN: miami::emmerson (host 3074::)      emmerson%miami.span at star.stanford.edu
UUCP: ...!ncar!umigw!steve               emmerson%miami.span at vlsi.jpl.nasa.gov
"Computers are like God in the Old Testament: lots of rules and no mercy"



More information about the Comp.lang.c mailing list