Author: Bo Persson
Date: 04:53:17 08/01/03
Go up one level in this thread
On July 30, 2003 at 17:46:35, Gerd Isenberg wrote:
>
>i see, therefore references in C++ or pointer in C++ or C are both "pass by
>reference". Is it not the same semantic and only a different syntax?
No, it is different semantics, but with the same effects.
C only has "pass by value", so you simulate "pass by reference" by going
indirect thru the pointer. The pointer itself is of course passed by value.
This what makes some people insist on writing f(int* p), because p is passed by
value, and its type is int*. :-)
>
>To be aware of the side effect if you write
>
>void foo(int &a) {...
> a = b;
>}
>
>The point of Dieter, because he dislikes references, is that with pointer syntax
>the side effect is obvious.
But if he doesn't want the actual parameter to be affected, he would of course
pass by const reference!
void foo(const int& a)
{
   a = b;
}
would be *very* obvious to the compiler.
(Of course, if the parameter really is as small as an int you should pass it by
value and not by const reference, but that's beside the point.)
Bo Persson
bop2@telia.com
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.