Re: tree example
- From: Barry Schwarz <schwarzb@xxxxxxxx>
- Date: Mon, 01 Dec 2008 19:23:17 -0800
On Mon, 1 Dec 2008 21:03:33 -0500, "Bill Cunningham"
<nospam@xxxxxxxxxxxxx> wrote:
Can anyone tell me what the (char *) is on page 143 kandr2 ? iinning to
understand the tree example but no what I just memtioned.
The only occurrence of the string "(char *)" in page 143 is a cast
applied to the return value of malloc. In the errata to K&R II, they
acknowledge that malloc and it siblings do not need this type of cast.
This code is a carry over from the pre-ANSI days when malloc returned
a char*.
This entire block of code is an implementation of the strdup function
which is used on page 141. Other than the fact that the addtree
function calls strdup, the function is not related to trees at all. It
merely copies the 'source' string (whose address is passed in an
argument) into a dynamically allocated block of memory.
--
Remove del for email
.
- Follow-Ups:
- Re: tree example
- From: Bill Cunningham
- Re: tree example
- References:
- tree example
- From: Bill Cunningham
- tree example
- Prev by Date: Re: void * and explicit cast
- Next by Date: Re: Compiler Warning
- Previous by thread: Re: tree example
- Next by thread: Re: tree example
- Index(es):
Relevant Pages
|