ANSI C questions (parameters, structure assignment)

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Fri Aug 24 15:24:27 AEST 1990


In article <352 at saxony.pa.reuter.COM>, dgil at pa.reuter.COM (Dave Gillett) writes:
: In <1081.26d26274 at desire.wright.edu> demon at desire.wright.edu writes:
: >struct_thing -= still_more_struct;
: >struct_thing *= even_more_struct;
: 
:      Recall that "x -= y" is equivalent to "x = x - y".  Will your VAX C let
: you get away with "struct_thing = struct_thing - still_more_struct"?  How
: have you declared "struct_thing" that lets it both (a) be a structure, and 
: (b) be in the domain of subtraction, which normally works on *numbers*???

Let that stand as typical of the answers.

I'd like to point out that given
	struct SomeTag this, that;
statements like
	this += that, this -= that, this *= that
and so on are perfectly reasonable things to do as such.  In COBOL,
	ADD CORRESPONDING THIS TO THAT.
	SUBTRACT CORRESPONDING THIS FROM THAT.
and so on will do the trick.  Given the equivalent of
	struct { int a, b; float c; } x;
	struct { int b, c, d; } y;
the COBOL equivalent of x += y would be
	ADD CORRESPONDING y TO x.
which would do
    /*	x.a : no change, as there is no y.a field */
	x.b += y.b;
	x.c += y.c;	/* only the names have to match */
    /*  y.d : not used, as there is no x.d field */

As it happens, this facility is not present in C.  There is nothing in
the language which would make it especially difficult to implement, it's
just that nobody ever thought it worth while.  It was a sensible question.

-- 
The taxonomy of Pleistocene equids is in a state of confusion.



More information about the Comp.lang.c mailing list