Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #19850

Re: What standard library functions must deal with allocated memory?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: What standard library functions must deal with allocated memory?
Date 2012-04-23 14:04 -0700
Organization None to speak of
Message-ID <ln397up3cm.fsf@nuthaus.mib.org> (permalink)
References <4f9598df$0$20194$426a74cc@news.free.fr> <dj8bp7tjbhb1i2d67rnh5qviqf9t2ptetu@4ax.com>

Show all headers | View raw


Barry Schwarz <schwarzb@dqel.com> writes:
> On Mon, 23 Apr 2012 20:01:49 +0200, Francois Grieu <fgrieu@gmail.com>
> wrote:
>
>>I'm trying to list all the standard C99/C2011 library functions that, by
>>design, must deal with allocated memory in any way.
>>
>>I've seen calloc malloc realloc free. Is there any other?
>>If strdup was a standard function (it is not), it would be in my list.
>
> strdup doesn't really "deal" with allocated memory so much as it uses
> the allocated memory malloc provided.  If you are going to include all
> the functions that call malloc et al then you may need to add:
>
>      fopen and fclose if the FILE* returned is allocated dynamically.
>
>      memmove and wmemmove if the "as if temporary array" is allocated
> dynamically.

fopen, fclose, memmove, and wmmemmove, *might* use allocated
memory (via malloc or something similar), but not in any way that
a programmer can or should be concerned with.  For example, passing
a FILE* that was returned by fopen to free has undefined behavior.
(And memmove and wmemmove are more likely to simply copy in reverse
order if the source and destination happen to overlap.)

For that matter, any standard library function might allocate and
deallocate memory behind the scenes.

> It is not a library function but do you want to include variable
> length arrays as dealing with allocated memory in some way?

Depends on what you mean by "allocated" -- and fixed-size arrays,
or any other declared objects, have the same issue.  VLAs do not
have allocated storage duration; I'm not sure if that's the criterion
Francois is most concerned with.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What standard library functions must deal with allocated memory? Francois Grieu <fgrieu@gmail.com> - 2012-04-23 20:01 +0200
  Re: What standard library functions must deal with allocated memory? James Kuyper <jameskuyper@verizon.net> - 2012-04-23 14:17 -0400
    Re: What standard library functions must deal with allocated memory? Francois Grieu <fgrieu@gmail.com> - 2012-04-23 20:37 +0200
  Re: What standard library functions must deal with allocated memory? Barry Schwarz <schwarzb@dqel.com> - 2012-04-23 12:26 -0700
    Re: What standard library functions must deal with allocated memory? Keith Thompson <kst-u@mib.org> - 2012-04-23 14:04 -0700
      Re: What standard library functions must deal with allocated memory? Robert Wessel <robertwessel2@yahoo.com> - 2012-04-23 17:15 -0500
    Re: What standard library functions must deal with allocated memory? Francois Grieu <fgrieu@gmail.com> - 2012-04-23 23:18 +0200
      Re: What standard library functions must deal with allocated memory? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-23 21:55 -0400
        Re: What standard library functions must deal with allocated memory? Quentin Pope <nospam@nospam.invalid> - 2012-04-24 02:07 +0000
          Re: What standard library functions must deal with allocated memory? Dr Nick <3-nospam@temporary-address.org.uk> - 2012-04-24 07:05 +0100
  Re: What standard library functions must deal with allocated memory? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-04-24 00:38 -0700
    Re: What standard library functions must deal with allocated memory? Keith Thompson <kst-u@mib.org> - 2012-04-24 22:24 -0700
      Re: What standard library functions must deal with allocated memory? pete <pfiland@mindspring.com> - 2012-04-25 08:04 -0400
      Re: What standard library functions must deal with allocated memory? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-04-28 04:09 -0700
    Re: What standard library functions must deal with allocated memory? Stephen Sprunk <stephen@sprunk.org> - 2012-04-25 01:19 -0500
      Re: What standard library functions must deal with allocated memory? pete <pfiland@mindspring.com> - 2012-04-25 07:55 -0400
  Re: What standard library functions must deal with allocated memory? gordonb.ho66c@burditt.org (Gordon Burditt) - 2012-04-27 20:44 -0500

csiph-web