[comp.lang.c++] Automatic Dereferencing

gjditchfield@watmsg.uwaterloo.ca (Glen Ditchfield) (08/03/90)

In article <1990Aug2.234350.6507@ingres.Ingres.COM> jas@llama.Ingres.COM (Jim Shankland) writes:
>Consider this puzzle:  suppose that assignment and initialization semantics
>in C++ were altered such that referencing and dereferencing were performed
>implicitly as needed.  That is, given:
>
>X x, *xp;
>
>you could say:
>
>x = xp;		// rhs implicitly converted to *xp
>xp = x;		// rhs implicitly converted to &x
>
>just as you can currently say:
>
>int i, double d;
>...
>d = i;		// i implicitly converted to (double) i
>
>Some 60's language -- Algol 68? -- did this.

	... For example, if x and y are reference variables,
			x := y,
	obviously changes the value of x, but a statement in ALGOL 68 like
			x := y + 1;
	may change the value of a, or b, or any other variable of
	appropriate type:  One variable it cannot possibly change is x!

		-- C.A.R. Hoare, "Recursive Data Structures",
		   International Journal of Computer and Information
		   Sciences, v4, #2, 1975

>... As near as I can tell, this makes the need for references disappear
>altogether.

This seems to be one of those neat ideas that doesn't work well in
practice.  "Early Experience with Mesa" (CACM, august 1977, pp. 540-553)
discusses these coercions and "deproceduring":
	int i;
	int f(void);
	i = f;		/* legal; implicitly calls f. */
The authors report that "reactions of Mesa's early users to this proposal
ranged from lukewarm to strongly negative...competent and experienced
programmers seem to believe that coercion rules make their programs less
understandable and thus less reliable and efficient".  It also has the
effect of converting type errors into runable but possibly incorrect code.

    Glen Ditchfield  gjditchfield@violet.uwaterloo.ca  Office: DC 2517
Dept. of Computer Science, U of Waterloo, Waterloo, Ontario, Canada, N2L 3G1
	      These opinions have not been tested on animals.