passing reference to pointer

S

softdeveloper007

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!
 
C

Chris M. Thomasson

softdeveloper007 said:
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;
 
W

WANG Cong

softdeveloper007 said:
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++.
 
J

Jens Thoms Toerring

softdeveloper007 said:
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
 
C

Chris M. Thomasson

Chris M. Thomasson said:
softdeveloper007 said:
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.
 
M

Martin Ambuhl

softdeveloper007 said:
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.
 
S

softdeveloper007

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.
 
I

Ian Collins

softdeveloper007 said:
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.
 
S

softdeveloper007

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"?
 
D

Dik T. Winter

>

>
> 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

Ian Collins

softdeveloper007 wrote:

Please don't top-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.
 
S

softdeveloper007

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. :)


 
N

Nate Eldredge

softdeveloper007 said:
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.
 
S

softdeveloper007

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.
 
S

softdeveloper007

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!:))
 
S

softdeveloper007

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

aha! got to love the attitude on that. thumbs up!
 
S

softdeveloper007

softdeveloper007 said:



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. :)
 
G

Guest

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?

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.
 
S

softdeveloper007

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


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


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.

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?
 
S

softdeveloper007

softdeveloper007 said:



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. :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top