Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > pointer question

Reply
Thread Tools

pointer question

 
 
Bill Cunningham
Guest
Posts: n/a
 
      03-19-2013
Barry Schwarz wrote:
> On Sun, 17 Mar 2013 17:00:51 -0400, "Bill Cunningham"
> <(E-Mail Removed)> wrote:
>
> snip
>
>> Thanks Pete for your example. I will study it and use it. I have
>> been reading about linked lists lately and I want to get down
>> pointers to pointers before trying something so complicated. For me
>> anyway.

>
> Why do you think you need pointers to pointers to use linked lists?
>
> A linked list consists of a string of nodes which are usually
> implemented as structures. Each structure will contain at least one
> pointer which points to the next structure in the list.
>
> Where would an int** fit in this design?


the int ** was just being used in an example that was not a linked list
example. After a struct describing a node has been written some kind of
"push" function has to push nodes into the chain of nodes. That's where my
tutorial mentions pointer to pointers.

Bill


 
Reply With Quote
 
 
 
 
Bill Cunningham
Guest
Posts: n/a
 
      03-19-2013
Barry Schwarz wrote:
> On Sun, 17 Mar 2013 17:00:51 -0400, "Bill Cunningham"
> <(E-Mail Removed)> wrote:
>
> snip
>
>> Thanks Pete for your example. I will study it and use it. I have
>> been reading about linked lists lately and I want to get down
>> pointers to pointers before trying something so complicated. For me
>> anyway.

>
> Why do you think you need pointers to pointers to use linked lists?
>
> A linked list consists of a string of nodes which are usually
> implemented as structures. Each structure will contain at least one
> pointer which points to the next structure in the list.
>
> Where would an int** fit in this design?


The .pdf on this page is what I'm going by. It seems to be the simplest.
http://cslibrary.stanford.edu/103/




 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      03-20-2013
On Tue, 19 Mar 2013 13:32:41 -0400, "Bill Cunningham"
<(E-Mail Removed)> wrote:

>Barry Schwarz wrote:
>> On Sun, 17 Mar 2013 17:00:51 -0400, "Bill Cunningham"
>> <(E-Mail Removed)> wrote:
>>
>> snip
>>
>>> Thanks Pete for your example. I will study it and use it. I have
>>> been reading about linked lists lately and I want to get down
>>> pointers to pointers before trying something so complicated. For me
>>> anyway.

>>
>> Why do you think you need pointers to pointers to use linked lists?
>>
>> A linked list consists of a string of nodes which are usually
>> implemented as structures. Each structure will contain at least one
>> pointer which points to the next structure in the list.
>>
>> Where would an int** fit in this design?

>
> The .pdf on this page is what I'm going by. It seems to be the simplest.
>http://cslibrary.stanford.edu/103/


The tutorial loses credibility as soon as it states that a pointer
stores a reference, especially since the term has a specific meaning
in C++ which the tutorial claims to be relevant for.

While that tutorial does describe how a function can alter a variable
in the calling function by receiving a pointer to that variable, the
tutorial's claim that this is the traditional way to write a push
function seems suspect. Instead of having the push function return
void, the tradition I'm familiar with would have it return a pointer
to the head of the list and eliminate the need for a pointer to
pointer. This eliminates both the need for a pointer to pointer and
the unnecessary indirection within the push function at the cost of
using the push function in an assignment statement. In other words,
instead of calling push with
push(&head, data);
I would call it with
head = push(head,data);
This provides the additional flexibility of storing the return value
in a pointer different than the one passed as an argument.

--
Remove del for email
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-20-2013
Barry Schwarz <(E-Mail Removed)> writes:
> On Tue, 19 Mar 2013 13:32:41 -0400, "Bill Cunningham"
> <(E-Mail Removed)> wrote:

[...]
>> The .pdf on this page is what I'm going by. It seems to be the simplest.
>>http://cslibrary.stanford.edu/103/

>
> The tutorial loses credibility as soon as it states that a pointer
> stores a reference, especially since the term has a specific meaning
> in C++ which the tutorial claims to be relevant for.

[...]

I haven't looked at the tutorial, but N1570 6.2.5p20 says:

A pointer type describes an object whose value provides a
reference to an entity of the referenced type.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      03-20-2013
pete wrote:
> Barry Schwarz wrote:
>>
>> On Tue, 19 Mar 2013 13:32:41 -0400, "Bill Cunningham"
>> <(E-Mail Removed)> wrote:
>>
>>> Barry Schwarz wrote:
>>>> On Sun, 17 Mar 2013 17:00:51 -0400, "Bill Cunningham"
>>>> <(E-Mail Removed)> wrote:
>>>>
>>>> snip
>>>>
>>>>> Thanks Pete for your example. I will study it and use it. I
>>>>> have been reading about linked lists lately and I want to get down
>>>>> pointers to pointers before trying something so complicated. For
>>>>> me anyway.
>>>>
>>>> Why do you think you need pointers to pointers to use linked lists?
>>>>
>>>> A linked list consists of a string of nodes which are usually
>>>> implemented as structures. Each structure will contain at least
>>>> one pointer which points to the next structure in the list.
>>>>
>>>> Where would an int** fit in this design?
>>>
>>> The .pdf on this page is what I'm going by. It seems to be the
>>> simplest. http://cslibrary.stanford.edu/103/

>>
>> The tutorial loses credibility as soon as it states that a pointer
>> stores a reference, especially since the term has a specific meaning
>> in C++ which the tutorial claims to be relevant for.
>>
>> While that tutorial does describe how a function can alter a variable
>> in the calling function by receiving a pointer to that variable, the
>> tutorial's claim that this is the traditional way to write a push
>> function seems suspect. Instead of having the push function return
>> void, the tradition I'm familiar with would have it return a pointer
>> to the head of the list and eliminate the need for a pointer to
>> pointer. This eliminates both the need for a pointer to pointer and
>> the unnecessary indirection within the push function at the cost of
>> using the push function in an assignment statement. In other words,
>> instead of calling push with
>> push(&head, data);
>> I would call it with
>> head = push(head,data);
>> This provides the additional flexibility of storing the return value
>> in a pointer different than the one passed as an argument.

>
> Using a return value makes the most sense to me too.
>
> The only time that I use a pointer parameter
> to achieve a side effect in the calling function,
> is when the return value is already being used for something else.
>
> The code in the tutorial
> never checks the return value of an allocation,
> for a null pointer.


Does anyone have any other suggestions for a good C tutorial on this. I
have invested so much time in C if I can't eventually grasp it the thing to
look at would be C++. But this isn't a C issue I don't believe so much as a
algorithm issue in C.

Bill


 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      03-21-2013
Shao Miller wrote:

> A tutorial on linked lists or on multiple levels of indirection with
> pointers? I agree with you if you are saying that linked lists can be
> implemented with C, but are not intrinsic to C.


That's pretty much what I'm saying.

Bill


 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      03-21-2013
On Wed, 20 Mar 2013 16:01:11 -0400, "Bill Cunningham"
<(E-Mail Removed)> wrote:

snip

> Does anyone have any other suggestions for a good C tutorial on this. I
>have invested so much time in C if I can't eventually grasp it the thing to
>look at would be C++. But this isn't a C issue I don't believe so much as a
>algorithm issue in C.


If you are having trouble with the C concepts, C++ will not make
things any easier.

--
Remove del for email
 
Reply With Quote
 
Öö Tiib
Guest
Posts: n/a
 
      03-21-2013
On Wednesday, 20 March 2013 22:01:11 UTC+2, Bill Cunningham wrote:
> Does anyone have any other suggestions for a good C tutorial on this. I
> have invested so much time in C if I can't eventually grasp it the thing to
> look at would be C++. But this isn't a C issue I don't believe so much as a
> algorithm issue in C.


C++ is often considered "monstrously complex" by fans of other languages
because it adds a lot of features to C. With "a lot" I mean *A LOT*.
Classes, virtual functions, operator overloading, multiple
inheritance, exceptions, templates, lambda functions etc. C++ standard
library is also quite large so it takes some time to learn to use it.

Most C programs actually compile on C++ compilers with very little changes
(if any) so most of the complexity of C is legal in C++.

You may want to consider some scripting language like Python, that lot
of people say is easy to use.
 
Reply With Quote
 
blmblm@myrealbox.com
Guest
Posts: n/a
 
      03-22-2013
In article <514a1582$0$10404$(E-Mail Removed)>,
Bill Cunningham <(E-Mail Removed)> wrote:

[ snip ]

> Does anyone have any other suggestions for a good C tutorial on this. I
> have invested so much time in C if I can't eventually grasp it the thing to
> look at would be C++. But this isn't a C issue I don't believe so much as a
> algorithm issue in C.
>


I agree with the others who have said that if you're having trouble
with C it's unlikely that moving to C++ will help -- it's a much
bigger and more complicated language, with pretty much all the warts
of C, so -- how do you think it would be better?

I'm inclined to agree, though, that the problems you're having are
not necessarily language-specific -- C is probably one of the more
difficult languages to start with, but based on your history of
posts here I'm inclined to think that the problems are not so much
with the specifics of C as with, oh, "algorithmic thinking" maybe.
Possibly it's a result of the medication you're taking. Whether
switching to a different language would help -- I guess I'm not
optimistic, but I'd be glad to be proved wrong.

One thing I'm curious about, though:

A while back you posted to comp.lang.fortran asking about
introductory and/or tutorial material. I'd be interested in hearing
about how/whether you followed up on that. ?

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      03-22-2013
(E-Mail Removed) wrote:

[snip]

> A while back you posted to comp.lang.fortran asking about
> introductory and/or tutorial material. I'd be interested in hearing
> about how/whether you followed up on that. ?


I figured I've come this far so move on. And I think you are right. If I
knew fortran I still wouldn't know much to *do* with it or how to do
anything with it. I know what I'd like to do but lack the knowledge. I
mentioned C++ because it is much higher level mainly.

Bill


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to an array vs pointer to pointer subramanian100in@yahoo.com, India C Programming 5 09-23-2011 10:28 AM
Pointer to pointer or reference to pointer A C++ 7 07-05-2011 07:49 PM
Pointer to pointer Vs References to Pointer bansalvikrant@gmail.com C++ 4 07-02-2009 10:20 AM
passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer jimjim C Programming 16 03-27-2006 11:03 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM



Advertisments