Barry Schwarz <> writes:
> On Mon, 23 Apr 2012 20:01:49 +0200, Francois Grieu <>
> 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- <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"