passing reference to pointer

Discussion in 'C Programming' started by softdeveloper007, Feb 15, 2009.

  1. Hi,

    I am stuck here and need some inputs. To cut it short and simple:

    void func1( )
    {
    int* p1, p2;
    ....

    func2 (p1, p2);
    ...

    }

    void func2 (int*& pt1, int*& pt2)
    {

    }

    I got: "error LNK2001: unresolved external symbol...fatal error
    LNK1120: 1 unresolved externals"

    but problem is gone by simply changing it to ptr to ptr:

    void func1( )
    {
    int* p1, p2;
    ....

    func2 (&p1, &p2);
    ...

    }

    void func2 (int** pt1, int** pt2)
    {

    }

    compiler: visual studio6.0.

    Any pointer, please? thanks!
     
    softdeveloper007, Feb 15, 2009
    #1
    1. Advertising

  2. "softdeveloper007" <> wrote in message
    news:...
    > Hi,
    >
    > I am stuck here and need some inputs. To cut it short and simple:
    >
    > [...]
    >
    > but problem is gone by simply changing it to ptr to ptr:
    >
    > void func1( )
    > {
    > int* p1, p2;
    > ....
    >
    > func2 (&p1, &p2);
    > ...
    >
    > }
    >
    > void func2 (int** pt1, int** pt2)
    > {
    >
    > }
    >
    > compiler: visual studio6.0.
    >
    > Any pointer, please? thanks!



    Your initial code was in C++. BTW, `p2' is not a pointer to an `int', it is
    an `int'... Change the line to:

    int *p1, *p2;


    Or, IMVHO:


    int* p1;
    int* p2;
     
    Chris M. Thomasson, Feb 15, 2009
    #2
    1. Advertising

  3. softdeveloper007

    WANG Cong Guest

    softdeveloper007 wrote:

    > Hi,
    >
    > I am stuck here and need some inputs. To cut it short and simple:
    >
    > void func1( )
    > {
    > int* p1, p2;


    Probably you want:

    int *p1, *p2;

    > ....
    >
    > func2 (p1, p2);
    > ...
    >
    > }
    >
    > void func2 (int*& pt1, int*& pt2)
    > {
    >
    > }


    C doesn't have references, try comp.lang.c++.
     
    WANG Cong, Feb 15, 2009
    #3
  4. softdeveloper007 <> wrote:
    > I am stuck here and need some inputs. To cut it short and simple:


    > void func1( )
    > {
    > int* p1, p2;
    > ....
    > func2 (p1, p2);
    > ...
    > }


    > void func2 (int*& pt1, int*& pt2)
    > {
    > }


    > I got: "error LNK2001: unresolved external symbol...fatal error
    > LNK1120: 1 unresolved externals"


    > but problem is gone by simply changing it to ptr to ptr:


    > void func1( )
    > {
    > int* p1, p2;


    I guess you meant

    int *p1, *p2;

    otherwise the second variable won't be a pointer but a simple
    int.

    > ....
    > func2 (&p1, &p2);
    > ...
    > }


    > void func2 (int** pt1, int** pt2)
    > {
    > }


    > Any pointer, please? thanks!


    There are no "references" in C, you must be getting this
    mixed up with C++. Thus the first version won't compile
    with a C compiler while the second does. If you actually
    want to use C++ you must use a C++ compiler or, if your
    compiler does both, invoke it in C++ mode (many of those
    decide what to use according to the file extension, try
    e.g. '.cpp' or a '.C' instead of '.c'). But then you
    also will be better served when asking in comp.lang.c++
    instead;-)
    Regards, Jens
    --
    \ Jens Thoms Toerring ___
    \__________________________ http://toerring.de
     
    Jens Thoms Toerring, Feb 15, 2009
    #4
  5. "Chris M. Thomasson" <> wrote in message
    news:cgQll.3096$...
    > "softdeveloper007" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> I am stuck here and need some inputs. To cut it short and simple:
    >>
    >> [...]
    >>
    >> but problem is gone by simply changing it to ptr to ptr:
    >>
    >> void func1( )
    >> {
    >> int* p1, p2;
    >> ....
    >>
    >> func2 (&p1, &p2);
    >> ...
    >>
    >> }
    >>
    >> void func2 (int** pt1, int** pt2)
    >> {
    >>
    >> }
    >>
    >> compiler: visual studio6.0.
    >>
    >> Any pointer, please? thanks!

    >
    >
    > Your initial code was in C++.


    > [...]



    You also need to declare or define `func2()' before `func1()' or else the
    compiler will think `func2()' is an external function returning an `int';
    not good.
    ______________________________________________________
    /* void func2(int**, int**); */


    void func1()
    {
    int* p1;
    int* p2;
    func2(&p1, &p2);
    }


    void func2(int** pt1, int** pt2)
    {

    }


    int main(void) {
    func1();
    return 0;
    }

    ______________________________________________________


    Un-comment the declaration, and you should see no warnings and/or errors.
     
    Chris M. Thomasson, Feb 15, 2009
    #5
  6. softdeveloper007 wrote:

    > I am stuck here and need some inputs. To cut it short and simple:


    You may be confused about either what language you are using or what
    newsgroup you have posted to.

    This newsgroup is for the C programming language. The constructs you
    are using are syntax errors in that language. The extremely ugly form
    of "int *& pt1" belongs to a (at least) the different programming
    language C++. In either language the use of a function returning other
    than an int without a prior declaration is a serious error. It is more
    serious in C after 1999 or in C++, since neither has even the implicit
    int declaration that C89 had.
     
    Martin Ambuhl, Feb 15, 2009
    #6
  7. guys, thanks for all your inputs.

    first of all, i'd like to apologize for the typo of missing * ahead of
    p2 declaration that causes confusion.

    i tried to make it as simple as possible. the original problem was
    bubble-sorting the linked list by passing two pointers to nodes to a
    swapping function.

    it seems to me that, in order to properly step in the original
    pointers thru the list, the two pointers should be passed by value
    instead of reference to pointers,in other words, the pointers in the
    caller would remain pointing to the same memory location, and not be
    affected by swapping function, sounds right, right?

    but it seemed, the pace that the pointer walks in the caller is
    affected by the swapping function and thus steps in 2 steps (instead
    of 1) each time due to some reason.

    i knew simply swapping the value instead of re-arranging the nodes
    would be a much simpler way but that's not my choice here due to other
    restrictions.

    thanks.
     
    softdeveloper007, Feb 16, 2009
    #7
  8. softdeveloper007

    Ian Collins Guest

    softdeveloper007 wrote:
    > guys, thanks for all your inputs.


    In future, please don't multi-post. You asked this question on at least
    three groups. If a question is appropriate for more than one group
    (which is rare), cross-post.

    --
    Ian Collins
     
    Ian Collins, Feb 16, 2009
    #8
  9. in addition to this C group, i also posted it on two other C++ groups.
    with due respect, as long as it fits, i don't see the reason why not,
    saving valuable resources for posts like "bikini babes"?

    On Feb 15, 4:46 pm, Ian Collins <> wrote:
    > softdeveloper007 wrote:
    > > guys, thanks for all your inputs.

    >
    > In future, please don't multi-post. You asked this question on at least
    > three groups. If a question is appropriate for more than one group
    > (which is rare), cross-post.
    >
    > --
    > Ian Collins
     
    softdeveloper007, Feb 16, 2009
    #9
  10. In article <> softdeveloper007 <> writes:
    >
    > On Feb 15, 4:46 pm, Ian Collins <> wrote:
    > > softdeveloper007 wrote:
    > > > guys, thanks for all your inputs.

    > >
    > > In future, please don't multi-post. You asked this question on at least
    > > three groups. If a question is appropriate for more than one group
    > > (which is rare), cross-post.

    >
    > in addition to this C group, i also posted it on two other C++ groups.
    > with due respect, as long as it fits, i don't see the reason why not,
    > saving valuable resources for posts like "bikini babes"?


    You do not understand what cross-posting is?
    --
    dik t. winter, cwi, science park 123, 1098 xg amsterdam, nederland, +31205924131
    home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
     
    Dik T. Winter, Feb 16, 2009
    #10
  11. softdeveloper007

    Ian Collins Guest

    softdeveloper007 wrote:

    Please don't top-post!

    > On Feb 15, 4:46 pm, Ian Collins <> wrote:
    >> softdeveloper007 wrote:
    >>> guys, thanks for all your inputs.

    >> In future, please don't multi-post. You asked this question on at least
    >> three groups. If a question is appropriate for more than one group
    >> (which is rare), cross-post.


    > in addition to this C group, i also posted it on two other C++ groups.
    > with due respect, as long as it fits, i don't see the reason why not,
    > saving valuable resources for posts like "bikini babes"?
    >

    My point was you should cross-post. Otherwise people on one group waste
    their time answering what has already been answered elsewhere.

    --
    Ian Collins
     
    Ian Collins, Feb 16, 2009
    #11
  12. multi-posting? by the name, i guess i was, what's "so much worse"
    about it as long as it fits the topic? in light of the fact that not
    everyone is multi-subscriber.:)...always good to learn. :)


    On Feb 15, 8:49 pm, Golden California Girls <>
    wrote:
    > Dik T. Winter wrote:
    > > In article <> softdeveloper007 <> writes:

    >
    > > > On Feb 15, 4:46 pm, Ian Collins <> wrote:
    > > > > softdeveloper007 wrote:
    > > > > > guys, thanks for all your inputs.

    >
    > > > > In future, please don't multi-post. You asked this question on at least
    > > > > three groups. If a question is appropriate for more than one group
    > > > > (which is rare), cross-post.

    >
    > > > in addition to this C group, i also posted it on two other C++ groups.
    > > > with due respect, as long as it fits, i don't see the reason why not,
    > > > saving valuable resources for posts like "bikini babes"?

    >
    > > You do not understand what cross-posting is?

    >
    > I'm not sure you do! I believe he is multi-posting and that is much worse than
    > cross posting.
     
    softdeveloper007, Feb 16, 2009
    #12
  13. [Meta] Re: passing reference to pointer

    softdeveloper007 <> writes:

    > multi-posting? by the name, i guess i was, what's "so much worse"
    > about it as long as it fits the topic? in light of the fact that not
    > everyone is multi-subscriber.:)...always good to learn. :)


    Multi-posting means posting separate messages to different groups with
    the same content. Cross-posting is posting the same message to multiple
    different groups all at once, by listing them together in the
    "Newsgroups:" header.

    When you cross-post, people who read more than one of the target groups
    will ordinarily see your message just once, rather than several
    different times (which forces them to wonder if it's really the same
    message, or a slightly different one). It also merges all the
    discussions together; multi-posting tends to lead to multiple
    independent and redundant discussions.

    That said, the best course of action is still to post to the single
    group whose topic is the best fit. That's the most courteous thing to
    do: it targets your message to those who are the most interested and
    doesn't waste the time of those who are less interested. Cross-posting
    is only appropriate when your post has serious relevance to several
    groups and you don't think any one of them would include a broad enough
    audience to address all its issues. And multi-posting is never
    appropriate.
     
    Nate Eldredge, Feb 16, 2009
    #13
  14. On Feb 15, 10:03 pm, Nate Eldredge <> wrote:
    > softdeveloper007 <> writes:
    > > multi-posting? by the name, i guess i was, what's "so much worse"
    > > about it as long as it fits the topic? in light of the fact that not
    > > everyone is multi-subscriber.:)...always good to learn. :)

    >
    > Multi-posting means posting separate messages to different groups with
    > the same content. Cross-posting is posting the same message to multiple
    > different groups all at once, by listing them together in the
    > "Newsgroups:" header.
    >
    > When you cross-post, people who read more than one of the target groups
    > will ordinarily see your message just once, rather than several
    > different times (which forces them to wonder if it's really the same
    > message, or a slightly different one). It also merges all the
    > discussions together; multi-posting tends to lead to multiple
    > independent and redundant discussions.
    >
    > That said, the best course of action is still to post to the single
    > group whose topic is the best fit. That's the most courteous thing to
    > do: it targets your message to those who are the most interested and
    > doesn't waste the time of those who are less interested. Cross-posting
    > is only appropriate when your post has serious relevance to several
    > groups and you don't think any one of them would include a broad enough
    > audience to address all its issues. And multi-posting is never
    > appropriate.


    now it's getting clearer....but still not crystal...
    just signed up in a rush and didn't have chance to figure out how to
    and how not to.
    the topics in my post covers call by reference, reference to pointer,
    linked list...which would be considered "appropriate" for both C, C++
    and even data structure groups if there are any. on one hand, one
    would like to have maximum possible exposure of his or her post for
    those who are interested from info-sharing perspective, on the other
    hand, courtesy and etiquette are necessary for not to "force" those
    who read it multiple times just to figure out the nuanced details if
    any.
    seems cross-posting is the way, but haven't figured out how to
    "listing them together in the
    "Newsgroups:" header".

    but anyway, thanks for clarifying.
     
    softdeveloper007, Feb 16, 2009
    #14
  15. On Feb 15, 10:28 pm, softdeveloper007 <>
    wrote:
    > On Feb 15, 10:03 pm, Nate Eldredge <> wrote:
    >
    >
    >
    > > softdeveloper007 <> writes:
    > > > multi-posting? by the name, i guess i was, what's "so much worse"
    > > > about it as long as it fits the topic? in light of the fact that not
    > > > everyone is multi-subscriber.:)...always good to learn. :)

    >
    > > Multi-posting means posting separate messages to different groups with
    > > the same content. Cross-posting is posting the same message to multiple
    > > different groups all at once, by listing them together in the
    > > "Newsgroups:" header.

    >
    > > When you cross-post, people who read more than one of the target groups
    > > will ordinarily see your message just once, rather than several
    > > different times (which forces them to wonder if it's really the same
    > > message, or a slightly different one). It also merges all the
    > > discussions together; multi-posting tends to lead to multiple
    > > independent and redundant discussions.

    >
    > > That said, the best course of action is still to post to the single
    > > group whose topic is the best fit. That's the most courteous thing to
    > > do: it targets your message to those who are the most interested and
    > > doesn't waste the time of those who are less interested. Cross-posting
    > > is only appropriate when your post has serious relevance to several
    > > groups and you don't think any one of them would include a broad enough
    > > audience to address all its issues. And multi-posting is never
    > > appropriate.

    >
    > now it's getting clearer....but still not crystal...
    > just signed up in a rush and didn't have chance to figure out how to
    > and how not to.
    > the topics in my post covers call by reference, reference to pointer,
    > linked list...which would be considered "appropriate" for both C, C++
    > and even data structure groups if there are any. on one hand, one
    > would like to have maximum possible exposure of his or her post for
    > those who are interested from info-sharing perspective, on the other
    > hand, courtesy and etiquette are necessary for not to "force" those
    > who read it multiple times just to figure out the nuanced details if
    > any.
    > seems cross-posting is the way, but haven't figured out how to
    > "listing them together in the
    > "Newsgroups:" header".
    >
    > but anyway, thanks for clarifying.


    that being said, unless you have posts like "bikini babes" you know
    everyone would be interested across-group (no blame for multi-posting
    on that:)), cross-posting is always a better choice than "multi-
    posting" (nah!:))
     
    softdeveloper007, Feb 16, 2009
    #15
  16. On Feb 15, 11:00 pm, Han from China <>
    wrote:
    > softdeveloper007 wrote:
    > > in addition to this C group, i also posted it on two other C++ groups.
    > > with due respect, as long as it fits, i don't see the reason why not,

    >
    > Don't worry about it. Some people substitute control of Usenet for
    > control of their lives. Do you honestly think anyone living a happy
    > life would give a damn whether someone multi-posts on Usenet? ;-) I
    > mean, picture it: A guy has financial security, is in great shape,
    > has a passionate relationship, owns a cute pet or two, and yet
    > has a neurotic reaction when you violate some Holy Usenet Rule -- not
    > going to happen in the real world.
    >
    > In this case, multi-posting had the advantage over cross-posting that
    > we wouldn't have to watch the usual lame bickering between the Net
    > Nannies on this group and the Net Nannies on the others.
    >
    > Yours,
    > Han from China
    >
    > --
    > "Only entropy comes easy." -- Anton Chekhov


    aha! got to love the attitude on that. thumbs up!
     
    softdeveloper007, Feb 16, 2009
    #16
  17. On Feb 15, 11:07 pm, Richard Heathfield <> wrote:
    > softdeveloper007 said:
    >
    > <snip>
    >
    > > just signed up in a rush and didn't have chance to figure out how
    > > to and how not to.

    >
    > Your best course of action, at this point, is to spend six months
    > reading every article in the newsgroups to which you have
    > subscribed (without posting any further articles). Why? Because
    > newsgroups - like any other communities - have a culture, and each
    > newsgroup's culture is slightly different, and it's good manners to
    > take notice of a community's culture when seeking to become a part
    > of that community. After six months or so of diligent reading of
    > every article posted in that group, you'll be sufficiently aware of
    > the community's customs that you can begin to post without fear of
    > ignorantly offending people. You will also have begun the process
    > of separating the truth-tellers from the liars, the trolls from the
    > non-trolls, and the knowledgeable from the ignorant, a useful
    > exercise in itself.
    >
    > If you think six months is far too long, you are clearly a hasty
    > fellow, in which case a full year would be more appropriate.
    >
    > (Note that this advice is not of my own making. It has been kicking
    > around Usenet much longer than I have.)
    >
    > --
    > Richard Heathfield <http://www.cpax.org.uk>
    > Email: -http://www. +rjh@
    > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > "Usenet is a strange place" - dmr 29 July 1999


    opinion is like asshole, everyone has one. but apparently your one
    exception. :)
     
    softdeveloper007, Feb 16, 2009
    #17
  18. softdeveloper007

    Guest

    On 16 Feb, 03:25, softdeveloper007 <> wrote:
    > On Feb 15, 4:46 pm, Ian Collins <> wrote:
    > > softdeveloper007 wrote:


    > in addition to this C group, i also posted it on two other C++ groups.


    since comp.lang.c is not a C++ you did not "post it on two
    other C++ groups"

    > with due respect, as long as it fits, i don't see the reason why not,
    > saving valuable resources for posts like "bikini babes"?


    You are an idiot. C and C++ are two different languages.
    Did you post your C++ question on a Fortran group?

    > > > > guys, thanks for all your inputs.


    glad to be of help.

    <snip>

    ps. answering question before my first coffee does not
    make me grumpy it makes me see the world more clearly.


    --
    Nick Keighley
     
    , Feb 16, 2009
    #18
  19. On Feb 15, 11:56 pm, wrote:
    > On 16 Feb, 03:25, softdeveloper007 <> wrote:
    >
    > > On Feb 15, 4:46 pm, Ian Collins <> wrote:
    > > > softdeveloper007 wrote:

    > > in addition to this C group, i also posted it on two other C++ groups.

    >
    > since comp.lang.c is not a C++ you did not "post it on two
    > other C++ groups"
    >
    > > with due respect, as long as it fits, i don't see the reason why not,
    > > saving valuable resources for posts like "bikini babes"?

    >
    > You are an idiot. C and C++ are two different languages.
    > Did you post your C++ question on a Fortran group?
    >
    > > > > > guys, thanks for all your inputs.

    >
    > glad to be of help.
    >
    > <snip>
    >
    > ps. answering question before my first coffee does not
    > make me grumpy it makes me see the world more clearly.
    >
    > --
    > Nick Keighley


    save the religious crap for yourself ok? did i say my question was "C+
    + question"? grow up! drink two or three gallons of milk, if that
    helps at all.

    get a life, will ya?
     
    softdeveloper007, Feb 16, 2009
    #19
  20. On Feb 16, 12:13 am, Richard Heathfield <> wrote:
    > softdeveloper007 said:
    >
    > <snip>
    >
    > > opinion is like asshole,

    >
    > You get to choose what you write, but I get to choose what I read
    > and whom I take seriously. So far, you're not doing very well.
    > Obviously you aren't required to be worried about that. (Equally,
    > I'm not required to be worried about your C questions.)
    >
    > --
    > Richard Heathfield <http://www.cpax.org.uk>
    > Email: -http://www. +rjh@
    > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > "Usenet is a strange place" - dmr 29 July 1999


    hehe, your disgruntled and wining (what a miserable life!:)) and your
    here suspecting others are not doing well? what a irony. :)
     
    softdeveloper007, Feb 16, 2009
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sam pal
    Replies:
    3
    Views:
    550
    E. Robert Tisdale
    Jul 16, 2003
  2. jimjim
    Replies:
    16
    Views:
    844
    Jordan Abel
    Mar 28, 2006
  3. pereges
    Replies:
    7
    Views:
    439
    pereges
    Jun 1, 2008
  4. A
    Replies:
    7
    Views:
    639
  5. Replies:
    2
    Views:
    150
Loading...

Share This Page