P
Peter Duniho
Despite you cannot pass the null as argument, which is ubequitous, the
most
frequent parameter in C.
You _can_ pass null as an argument. You just can't pass null as an
argument for a "ref" parameter.
Where do I tell that C# references are different from C++ references? I
was
speaking about the difference between "pointers" and "references"!
Since a "ref" parameter is essentially the same as C++'s "&" by-reference
parameter, and since the "ref" parameter type (along with "out" which isa
special case of "ref") is the only situation in which your complaint about
not being able to pass null is true, _that_ is "where you tell that C#
references are different from C++ references".
You brought it up. I'm just pointing out the fallacy in your complaint.
Very easily.
function (ref a) {
if (a != null)
a = new object();
}
b = null;
function(ref b);
The above code does _not_ leave "b" unmodified when an new value is
assigned. It does leave "b" unmodified in the example calling code, but
that's only because the function also does not assign a new value.
The null passed by reference is left unmodified ;-)
The null passed by reference would be left unmodified in any case. It's
only "b" that would be modified or not, as that's the variable passed by
reference.
The same effect would be
reached by different 'nulls'
NULL = new Object();
func(ref r) {
if (r != NULL)
r = returnVal;
}
I have no idea what you expect that code to do. You can't assign an
object reference ("new Object()") to "null". You haven't declared "NULL",
so I don't know if you mean that to be the same as "null", or something
entirely different.
.. and the water is wet. But I did not address this issue!
Which issue? I agree that you didn't specifically raise the question of
checking for null values. However, that _is_ really the only practical
difference between your apparent desire to pass something by a pointer to
the variable versus the C# "ref" parameter type.
In that respect, you certainly did by implication "address this issue".
Read it once
again:
It has
two disadvantages though: 1) you must declare a bogus reference
variable;
So too you must in C++, if using "by-reference" parameter passing.
and 2) initialize it before passing to the function, where you could
just
pass a 0 right away. Furthermore, it prevents you from using 'out'
arguments.[end quote]
What prevents you from using "out" arguments? The use of the "out"
parameter type is in fact how you can avoid having to initialize the
variable passed into the function.
Who argues that we should assign null (optional) arguments if the null
passed means "user does not want us to out anything"?
What do you mean by "assign null arguments"? You can't assign anything to
a null reference or pointer.
Because you read and respond on the thing I do not address.
The fact that you think my response isn't relevant to the thing you are
talking about is in fact the very evidence that you don't understand the
thing that you are talking about.
Pete