[net.lang.c] Array by value

minow@decvax.UUCP (Martin Minow) (08/19/83)

Arnold Robbins suggests adding the ` operator to C to mean
"array by value" as in:

    int a[10]; b[10];
    ...
	`a = `b;	/* I may have misrembmered the syntax */

There are several problems with this.  First, all C expressions
return a value, so I should be able to write statements such
as

	if ((`a = `b) != 0)

which is going to cause great pains for compiler writers.

The other problem is that this suggestion rejects one of the
primary C design philosophies -- that of making "easy things
easy and hard things hard".  Most compiler writers will
generate something like "`a = `b":

	_bcopy(&a[0], &b[0], sizeof a);

A suitably written _bcopy will run at memory speeds for all non-trivial
cases.

I am willing to bet that all the reasonable "array by value"
operations could be implemented just as efficiently by
a macro preprocessor.

I should also note that Andrew's other suggested operator, '$'
is valid in identifiers in Vax-11C, Decus C, and probably
a few other PDP-11 compilers running on Dec machines.  ('$' is
necessary to access system-wide variables on Dec operating
systems.)

Martin Minow
decvax!minow

hamilton@uiucuxc.UUCP (08/22/83)

#R:decvax:-17100:uiucuxc:21000005:000:432
uiucuxc!hamilton    Aug 21 17:32:00 1983

regarding the value of the array assignment expression, this
made me wonder what the compiler does for structure assignments.
i tried this (4.1a BSD cc):

    main()
    {
	struct { int x, y, z ; } a, b;

	if ((a = b) != 0)
	    ;
    }

and got the diagnostic "operands of != have incompatible types".
(btw, this compiler generated a movc3 instruction for the actual copy.)
	wayne ({decvax,ucbvax}!pur-ee!uiucdcs!uiucuxc!)hamilton

guy@rlgvax.UUCP (Guy Harris) (08/23/83)

The problem with the example you gave is that it was comparing the result
of the assignment operator (which is its LHS, i.e. a structure) with 0.
Structures and ints can't be compared; furthermore, structures can't be
compared because you can't just use a quick loop/string compare instruction
because it would compare any holes in the structure as well, so nobody has
implemented structure comparison.

	Guy Harris
	{seismo,mcnc,we13,brl-bmd,allegra}!rlgvax!guy