Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!umigw!steve From: steve@umigw.MIAMI.EDU (steve emmerson) Newsgroups: comp.lang.c Subject: Re: best way to return (char *) Message-ID: <352@umigw.MIAMI.EDU> Date: 23 Jun 89 12:45:04 GMT References: <7800013@gistdev> <18234@mimsy.UUCP> Reply-To: steve@umigw.miami.edu (steve emmerson) Distribution: na Organization: Rosenstiel School of Marine and Atmospheric Science Lines: 23 In article <18234@mimsy.UUCP> chris@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@umigw.miami.edu [128.116.10.1] SPAN: miami::emmerson (host 3074::) emmerson%miami.span@star.stanford.edu UUCP: ...!ncar!umigw!steve emmerson%miami.span@vlsi.jpl.nasa.gov "Computers are like God in the Old Testament: lots of rules and no mercy"