Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Pointer to pointer with lots of examples

Reply
Thread Tools

Pointer to pointer with lots of examples

 
 
Morris Dovey
Guest
Posts: n/a
 
      07-31-2006
sheroork (in m)
said:

| Can anyone help me in getting to understand pointer to pointer with
| examples?

Sagar...

The explanations posted so far look good. These two links make up
another example of how pointers to pointers might be used:

http://www.iedu.com/mrd/c/tokenize.c
http://www.iedu.com/mrd/c/tokfile.c

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto


 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      07-31-2006
Morris Dovey wrote:
> sheroork (in m)
> said:
>
> | Can anyone help me in getting to understand pointer to pointer with
> | examples?
>
> Sagar...
>
> The explanations posted so far look good. These two links make up
> another example of how pointers to pointers might be used:
>
> http://www.iedu.com/mrd/c/tokenize.c
> http://www.iedu.com/mrd/c/tokfile.c


They look more like an example of how not to write C to me.

Rather than having a tokenize.h containing the prototype for the
tokenize function it has the prototype repeated in tokfile.c. So you
have to maintain it in two places with no help from the compiler.

Using a file scope variable for the function to determine if a character
is a word separator or part of a word instead of passing it down. What
is worse, a single character name for it!

Assuming ASCII or similar character encoding instead of using the
portable standard is* functions.

Increasing the hard to follow coupling by using another file scope
variable s to hold a pointer to the character being processed. The
author seems to have a major objection to using parameters!

Using recursion for what could more simply be implemented with a for
loop, and the state being passed down via the afore mentioned file scope
variables instead of parameters!

That code is so needlessly convoluted that pointing a beginner at it is
tantamount to cruelty!
--
Flash Gordon
Still sigless on this computer.
 
Reply With Quote
 
 
 
 
sheroork
Guest
Posts: n/a
 
      07-31-2006
Thanks friends for all your time and knowledge you have posted.
I will be greatful for your postings.

Thanks,
Sagar

 
Reply With Quote
 
Tom St Denis
Guest
Posts: n/a
 
      07-31-2006
August Karlstrom wrote:
> sheroork wrote:
> > Can anyone help me in getting to understand pointer to pointer with
> > examples?

>
> int **p;
>
> p
> +---+
> | ? |
> +---+
>
> p = malloc(sizeof *p);
>
> p *p
> +---+ +---+
> | ----->| ? |
> +---+ +---+
>
> *p = malloc(sizeof **p);
>
> p *p **p
> +---+ +---+ +---+
> | ----->| ----->| ? |
> +---+ +---+ +---+
>
> **p = 7;
>
> p *p **p
> +---+ +---+ +---+
> | ----->| ----->| 7 |
> +---+ +---+ +---+


I, for one, welcome our ASCII art overlords.

Tom

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      07-31-2006
Richard Heathfield wrote:

> Scorpio said:


> > Sorry, I was mistaken and yes, August's code is correct.
> > But I actually meant: *p=malloc(sizeof(int));
> > Is something wrong with this?

>
> It will at least compile, but it's inferior to August's version,
> because you're nailing the type to the call, possibly causing a
> maintenance headache further down the line.



After all, we just got done diagnosing an incorrect malloc call in
another thread. The deference the target method isn't fool-proof, of
course, but it's closer. You still have the cut and paste problem, but
it's a tad more recognizable because you have the two variable names on
the same line, whereas the types are often widely separated.



Brian
 
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
Looking for lots of words in lots of files brad Python 9 06-19-2008 07:59 AM
RESUME EXAMPLES INFORMATION / CV EXAMPLES NOW AVAILABLE THROUGHRESUMEWRITERGUIDE.COM rawebadvert3 Computer Support 0 03-23-2008 04:19 AM
COVER LETTERS RESUME EXAMPLES AND CV EXAMPLES AVAILABLE CURRICULUM VITAE rawebadvert3 Computer Support 0 08-21-2007 03:07 AM
COVER LETTERS RESUME EXAMPLES AND CV EXAMPLES AVAILABLE rawebadvert3 Computer Support 0 05-25-2007 04:18 AM
Downloading lots and lots and lots of files coolneo Perl Misc 9 01-30-2007 02:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57