Re: Am I programming correctly with array parameter?
From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 08/29/04
- Next message: newbiecpp: "Makefile"
- Previous message: Francis Glassborow: "Re: Am I programming correctly with array parameter?"
- In reply to: Francis Glassborow: "Re: Am I programming correctly with array parameter?"
- Next in thread: Sam Sungshik Kong: "Re: Am I programming correctly with array parameter?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 29 Aug 2004 15:07:18 +0100
In article <kZiG4$LUXdMBFwqT@robinton.demon.co.uk>, Francis Glassborow
<francis@robinton.demon.co.uk> wrote:
> In article <290820041223102174%dt015a1979@mac.com.invalid>, Alwyn
> <dt015a1979@mac.com.invalid> writes
>
> >But there are cases where allocating memory within a function and
> >depending on the user to free it is unavoidable. Such cases must be
> >clearly and prominently documented, of course.
>
> I have no argument with that, but newcomers to the language probably
> lack the experience to identify those cases,
Here's one such case, which any beginner can understand, in my humble
opinion:
Standard C does not provide the POSIX 'strdup' function, perhaps for
the reason that the user needs to do the work of 'cleaning up' after
it. However, the fact remains that duplicating a string is something
one often has to do. So we can write our own:
char *dupstr(const char *source)
{
char *dest = malloc(strlen(source)+1);
if (dest != NULL)
strcpy(dest, source);
return dest;
}
> and simple emulating idioms
> they have used in other languages will hinder their progress.
Yes, of course, though it's not clear to me that this is what the OP
was doing in this instance. I believe he was just practising his newly
acquired ability to manipulate pointers.
Alwyn
- Next message: newbiecpp: "Makefile"
- Previous message: Francis Glassborow: "Re: Am I programming correctly with array parameter?"
- In reply to: Francis Glassborow: "Re: Am I programming correctly with array parameter?"
- Next in thread: Sam Sungshik Kong: "Re: Am I programming correctly with array parameter?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|