Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <4F97E61A.464@mindspring.com> (permalink) |
|---|---|
| Date | 2012-04-25 07:55 -0400 |
| From | pete <pfiland@mindspring.com> |
| Organization | PF |
| Newsgroups | comp.lang.c |
| Subject | Re: What standard library functions must deal with allocated memory? |
| References | <4f9598df$0$20194$426a74cc@news.free.fr> <14459967.23.1335253094679.JavaMail.geo-discussion-forums@yndm3> <jn851f$3r6$1@dont-email.me> |
Stephen Sprunk wrote:
>
> On 24-Apr-12 02:38, Malcolm McLean wrote:
> > בת×ריך ×™×•× ×©× ×™, 23 ב×פריל 2012 19:01:49 UTC+1, מ×ת Francois Grieu:
> >> 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.
> >
> > None of them, except for malloc(), realloc() and free() themselves.
> >
> > This appears to have been a deliberate design decision.
> > strdup() is an obvious candidate for a library function,
> > but including it would make
> > the string library dependent on an allocation
> > package being available.
>
> I thought it was a combination of wanting memory-allocation
> functions to be clearly identifiable as such
> and avoiding functions that were trivial
> combinations of other primitive functions already provided.
There's already at least a couple of string functions which are
trivial combinations of other primitive functions already provided.
char *
strcat(char *s1, const char *s2)
{
strcpy(strlen(s1) + s1, s2);
return s1;
}
char *
strpbrk(const char *s1, const char *s2)
{
s1 += strcspn(s1, s2);
return *s1 != '\0' ? (char *)s1 : NULL;
}
There's also some trivial repackaging declared in stdio.h
int
vprintf(const char *format, va_list arg)
{
return vfprintf(stdout, format, arg);
}
and also declared in ctype.h
int
isalpha(int c)
{
return islower(c) || isupper(c);
}
int
isalnum(int c)
{
return isdigit(c) || isalpha(c);
}
--
pete
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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