From: "Robert P. J. Day" <rpjday@mindspring.com>
To: Kelly Burkhart <kelly@kkcsm.net>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: how to implement routines that return general strings?
Date: Sat, 12 Aug 2006 05:36:51 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0608120534250.5194@localhost.localdomain> (raw)
In-Reply-To: <fa1e4ce70608111306k5bdb728an4a4d72f642030306@mail.gmail.com>
On Fri, 11 Aug 2006, Kelly Burkhart wrote:
> On 8/10/06, Scott <drmemory@3rivers.net> wrote:
> > With the caveat that I haven't done any serious programming in C for
> > many years: As I recall, I always used a protocol halfway between
> > these, as:
> >
> > char *func(size_t bufsiz)
> > {
> > char *retval = malloc (bufsiz);
> > if (retval == NULL) return (NULL);
> > /* whatever */
> > return (retval);
> > }
>
> This code is to live in a shared library and you wish for it to be
> portable then you may want to keep in mind the difficulties on some
> platforms of allocating memory in one shared library and freeing in
> another. If this concern is relevant to you, the above must be
> paired with void funcCleanup(char*).
obviously, if i chose to do it this way, i'd first check if a malloc()
had already been done, so i don't keep malloc()ing unnecessarily
(keeping a static pointer, naturally).
that would seem to be functionally equivalent to just declaring a
static array of characters within that routine, anyway.
rday
next prev parent reply other threads:[~2006-08-12 9:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-10 14:10 how to implement routines that return general strings? Robert P. J. Day
2006-08-10 17:12 ` Scott
2006-08-10 19:04 ` David Rientjes
2006-08-11 20:06 ` Kelly Burkhart
2006-08-12 9:36 ` Robert P. J. Day [this message]
2006-08-14 18:15 ` Scott
2006-08-10 21:07 ` Glynn Clements
2006-08-11 7:03 ` Raseel Bhagat
2006-08-11 18:36 ` Shorty Porty
-- strict thread matches above, loose matches on Subject: below --
2006-08-10 16:51 Khan, Ahmer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0608120534250.5194@localhost.localdomain \
--to=rpjday@mindspring.com \
--cc=kelly@kkcsm.net \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).