Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Malloc without free in linked list code |
| Date | 2015-04-14 16:10 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87d236kap2.fsf@bsb.me.uk> (permalink) |
| References | (2 earlier) <mgifcq$s1j$1@dont-email.me> <75576f60-87ab-4714-b12a-424796ae6e6e@googlegroups.com> <mgin7m$lqk$1@dont-email.me> <87r3rmkhh6.fsf@bsb.me.uk> <mgj3id$62k$1@dont-email.me> |
David Brown <david.brown@hesbynett.no> writes:
> On 14/04/15 14:43, Ben Bacarisse wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>
>>> On 14/04/15 10:45, Paul wrote:
>>>> On Tuesday, April 14, 2015 at 8:26:22 AM UTC+1, David Brown wrote:
>> <snip>
>>>>> struct node *CopyList(struct node *head)
>>>>> {
>>>>> struct node *current = head;
>>>>> struct node dummyTail = { .next = newList };
>>>>> struct node *tail = &dummyTail;
>>>>>
>>>>> while (current != NULL) {
>>>>> tail->next = malloc(sizeof(struct node));
>>>>> (tail->next)->data = current->data;
>>>>> (tail->next)->next = NULL;
>>>>> tail = tail->next;
>>>>> }
>>>>> return dummyTail.next;
>>>>> }
>>>>>
>>>>> That keeps the loop as short as your version, but eliminates the
>>>>> unpleasant double pointer.
>>
>> Personally, I don't see anything unpleasant about a double pointer
>
> It's a matter of taste and style, of course.
Of course. That was intended to be conveyed by saying "personally...".
>> but
>> you haven't really got rid of it, you've just declared it in a funny way
>> (that I think might be just as confusing as **) and accessed it using
>> two ->s instead of a * and a ->.
>
> No, I've got rid of the double pointer - the two -> in a row is a chain
> of nodes, rather than a pointer-to-a-pointer.
And this is going to be about terminology if we don't take care! Sure,
you've got rid of the pointer to a pointer, but not the double
indirection. You now point to something that holds the target pointer
at a offset that is not zero.
<snip>
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Malloc without free in linked list code Paul <pepstein5@gmail.com> - 2015-04-13 11:21 -0700
Re: Malloc without free in linked list code Lőrinczy Zsigmond <nospam@for.me> - 2015-04-13 20:45 +0200
Re: Malloc without free in linked list code Richard Heathfield <rjh@cpax.org.uk> - 2015-04-13 19:53 +0100
Malloc without free in linked list code asetofsymbols@gmail.com - 2015-04-13 12:05 -0700
Re: Malloc without free in linked list code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-13 21:58 +0100
Re: Malloc without free in linked list code David Brown <david.brown@hesbynett.no> - 2015-04-14 09:26 +0200
Re: Malloc without free in linked list code Paul <pepstein5@gmail.com> - 2015-04-14 01:45 -0700
Re: Malloc without free in linked list code David Brown <david.brown@hesbynett.no> - 2015-04-14 11:39 +0200
Re: Malloc without free in linked list code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-14 13:43 +0100
Re: Malloc without free in linked list code David Brown <david.brown@hesbynett.no> - 2015-04-14 15:10 +0200
Re: Malloc without free in linked list code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-14 16:10 +0100
Re: Malloc without free in linked list code David Brown <david.brown@hesbynett.no> - 2015-04-14 17:37 +0200
Re: Malloc without free in linked list code Keith Thompson <kst-u@mib.org> - 2015-04-14 11:44 -0700
Re: Malloc without free in linked list code David Brown <david.brown@hesbynett.no> - 2015-04-15 00:00 +0200
Re: Malloc without free in linked list code Richard Heathfield <rjh@cpax.org.uk> - 2015-04-14 20:12 +0100
Re: Malloc without free in linked list code David Brown <david.brown@hesbynett.no> - 2015-04-15 00:04 +0200
Re: Malloc without free in linked list code Richard Heathfield <rjh@cpax.org.uk> - 2015-04-15 00:20 +0100
Re: Malloc without free in linked list code Tim Rentsch <txr@alumni.caltech.edu> - 2015-04-16 15:46 -0700
Re: Malloc without free in linked list code David Brown <david.brown@hesbynett.no> - 2015-04-17 10:38 +0200
Re: Malloc without free in linked list code Tim Rentsch <txr@alumni.caltech.edu> - 2015-04-17 08:30 -0700
Re: Malloc without free in linked list code James Kuyper <jameskuyper@verizon.net> - 2015-04-14 08:04 -0400
Re: Malloc without free in linked list code Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-14 05:38 -0700
Re: Malloc without free in linked list code BGB <cr88192@hotmail.com> - 2015-04-14 10:31 -0500
Malloc without free in linked list code Chad <cdalten@gmail.com> - 2015-04-14 19:51 -0700
Re: Malloc without free in linked list code James Kuyper <jameskuyper@verizon.net> - 2015-04-14 23:10 -0400
csiph-web