Kai-Uwe Bux said:
Martin Jørgensen wrote:
-snip-
Ok, these were your original words. I would like to start with the
observation that the first sentence is true and stays true if you replace C
by C++:
In C++ you would get either a compiler error or warning if you don't
dereference the pointer when you want to access the value of the
pointed-to-value (the pointer in C++).
I don't see why you want to replace C by C++. Can you tell me why? I
don't see any problem with the original construction of the words...
Therefore, the first sentence is a little bit awkward a sentence to start a
paragraph that is meant to pinpoint a difference between C an C++.
I can't see that.
Now the second sentence: "That same thing is a reference in C++". For this
one, I just would like to ask what the phrase "That same thing" is supposed
to refer to. It should be something mentioned in the first sentence, right?
Yes! The pointer points to the address of the variable that is passed to
some function... That's why this sign "&" means the "address-of-operator".
And that explanation fully agrees with the the definition of "&":
"Definition: The address of operator, &, returns the address of a
variable or object.
Example:
int result; // Integer object.
int *pt; //Integer pointer
pt = &result; //Stores the address of result in the pointer, pt."
from
http://cplus.about.com/od/cprogrammin1/l/bldef_addofoper.htm
I already wrote this a couple of times, I believe - I feel just like
repeating myself over-and-over.
So: You need to dereference this pointer variable, in order to "access
the value of the pointed-to-value (the pointer in C)."
I can't see that should be so difficult to understand. Now, in C++ you
can pass arguments in a function header "by-reference" by using the
"&"-operator. You can have a function header like this:
return_type some_function( int &reference ) {..... }
and the "&reference" in cpp means: "accept a reference which is just
like an alias for the passed-by-variable".
C doesn't understands references. If it should accept a pointer it would be:
return_type some_function( int *reference ) {..... }
In the C language *THAT SAME THING* (remember my previously
explanations?): "&reference" means: "dont access the variable itself
directly. Instead pass the address of the variable, so it'll become a
pointer-to-variable."
You need to *DEREFERENCE* any pointer-to-variable in order to access the
values of those variables in C.
You *can't* have a construction like this in C:
return_type some_function( int &reference ) {..... }
So don't tell me that there isn't any difference between the 2
languages, like I thought somebody wrote earlier (could be that was just
some kind of "communication error", since I think everyone at least at
some moment agreed to this fact even though they wrote that there isn't
any difference - not easy to understand that)...
I'm not sure if this is a detailed enough explanation, but I really feel
really like I'm repeating myself too much... Still you should understand
it now, right?
Ok. Make your pick and find something in the first sentence that completes
the pattern
_________________ is a reference in C++.
I don't know what you're talking about, and I really don't feel like
playing silly games right now. Why don't you just tell whatever you
think instead of asking me to guess what you think (I can't guess what
you think anyway)?
I cannot find anything mentioned in the first sentence that matches this
requirement. The natural candidate would be the phrase "the pointer in C".
Then we would read:
the pointer in C is a reference in C++.
The pointer in C *dereferenced* corresponds to a reference in C++!
Now that line is odd, because C++ has pointers and those pointers work
exactly the same like pointers in C. So a pointer in C really corresponds
to a pointer in C++ and a reference in C++ simply has no counterpart in C.
The pointer in C *dereferenced* corresponds to a reference in C++!
That's what the whole discussion is all about, remember that?
You remember this talk about "automatic dereferencing"? What do you
think that talk was about? You couldn't have understood that could you?
That is fully consistent with my previous explanation, AFAICS. If you
think I somewhere wrote something wrong, perhaps you can tell me where
this is because I have a very hard time figuring out what you mean...
Still, you need to understand that this "&reference" isn't the variable
itself - it's the *address* of that variable. I don't think you
understood that from my previously explanation, but now I've given an
example above together with a pretty detailed explanation, so I think it
should be possible to understand it now.
Clearly, I did not understand what the phrase "That same thing" was supposed
to refer to.
You should just ask about it then, because you're really confusing me
with your guesses.
Please, do no exaggerate my claims. Of course the is a difference between C
and C++. And we already agreed on a wording to describe it:
I'm not sure if I exaggerated. You and "default user" both specifically
wrote something about "No difference between the 2 languages", but
instead you ought to express that ofcourse there is a very clear
difference between C and C++.
That would show that you at least understood something relevant in my
explanations...
So I *really* don't understand all of this talk with "no difference".
Like: When there is no difference between passing a pointer, why the
h*** do you then write about it as if it was relevant, when it's
absolutely *irrelevant*?
I just don't understand that... It's just making the discussion
*unnecessary* long and complicated and nobody is interested in that, I hope.
C++ has call by value and call by reference whereas C only has
call by value.
All the fuzz is just about the *additional* explanations that you propose.
It's *really* simple...
Hm, the only difference in how the &-operator *works* in C and C++ is that
you can overload operator&() in C++. The workings of the &-operator are
exactly the same: in both languages, it returns a pointer to the object
specified by its argument.
Irrelevant, I believe.
In particular, *when you pass a variable into a function with the
&-operator*, there is no difference in the C and C++ will handle this
function call (unless operator& was overloaded in C++). The difference
between the two languages is not something that shows *when you pass a
variable into a function with the &-operator*.
Irrelevant, I believe.
I believe that you ought not to bring all of these irrelevant topics
into the discussion, as they're just confusing more than they serve any
reasonable purpose.
Incomplete. Instead it should read:
If you want to call a function that modifies an object from the ambient
scope:
That discussion is irrelevant, AFAICS.
1) In C you pass the address of the object.
2) In C++ you do the same, or alternatively, you pass a reference for
the object. Which way you have to go is determined by the signature.
I don't disagree, but my explanation was enough for understanding and
realizing that there is a difference between C and C++, so what you're
writing is simply irrelevant and not something I intend to waste much
time on...
[snip]
And you don't see any difference?
I do. See above. The question is not *whether* there is a difference, but
how to phrase it.
You should try to concentrate on what is relevant here.
I do see that. I just don't find that wording particularly helpful.
Somehow I don't think you can see it even though you write it... Are you
sure you can see it, with my last 3 postings with pretty long explanations?
Moreover, this mental model led you to claims like: there is a difference
in how operator& works in C and C++ (besides its capacity for being
Wrong! I still don't understand all of your irrelevant talk about "how
operator& works in C and C++".
That's just irrelevant garbage... Where in my previous posts did you see
I wrote something about operator& ???
You need to cut down all this irrelevant talk... It's just confusing...
I suppose you just don't understand something in the previously
explanations and are making wild guesses... Please stop guessing,
because it's too confusing to read.
overloaded). Such claim is just false and a mental model leading to such
statements is of questionable value.
[snip]
But ofcourse it's no big deal if something was inaccurate written -
you're just fundamentally wrong when you say that there no difference
between passing something to a function in C and C++.
I did not say that. I wrote there is no difference with regard to the
following statement:
In C you would get either a compiler error or warning if you don't
dereference the pointer when you want to access the value of the
pointed-to-value (the pointer in C).
I really don't understand you... Sometimes you write that there isn't
any difference between the 2 languages. Like with the above statement.
But I clearly pointed out the difference I believe... And yet you don't
think there's a difference?
I do not think that one should explain a language *difference* using
sentences about C that just literally stay true when you replace C with
C++.
I dont understand one word of that. I never wanted to replace C with C++
(or was it the other way around?). You are the only one who talks about
replacing C and C++...
As I wrote earlier: You really need to cut down this irrelevant talk,
because some of it is really confusing...
Best regards / Med venlig hilsen
Martin Jørgensen