YAAO and `with'
Dick Dunn
rcd at opus.UUCP
Wed Dec 19 16:01:13 AEST 1984
> > Dean Rubine asked for a ->= operator,...
(Sorry about the grandparental nature of the reference for the followup.)
The desire for ->= (assign from subfield) comes from one case of a more
general desire--working on a referenced object in some convenient way.
Consider as an alternative something like the Pascal `with' clause. (No,
put down the torch, I don't mean to consider adding it to C! Just consider
it for a hypothetical language.) The semantics of `with', somewhat
simplified, is that in the form
with <reference>
do <statement>
<reference> must be a reference to a structure, and within <statement> the
fields of that structure are accessible without prefixing them with the
structure reference. For example (here, "^" is Pascal's pointer-de-
reference), one Pascal idiom is"
while p<>nil do with p^ do
begin
. . .
p := next;
end
where "next" is a field of the record referenced by p; without the `with'
the statement would have been written p := p^.next
The `with' is useful in a lot of other situations, such as filling in
several fields of the same record. The usual implementation is to grab a
pointer to the base of the structure, taking care of any address
calculations in the <reference>, and try to keep the pointer in a
register.
--
Dick Dunn {hao,ucbvax,allegra}!nbires!rcd (303)444-5710 x3086
...Nothing left to do but smile, smile, smile.
More information about the Comp.lang.c
mailing list