Self-modifying code
Steven Ryan
smryan at garth.UUCP
Wed Jul 27 04:44:45 AEST 1988
In article <1075 at garth.UUCP> smryan at garth.UUCP (Steven Ryan) writes:
>>If the machine allows a change to one variable (an array, say) to
>>affect some other unrelated variable, then it is not conforming to
>>the intent of my program. In fact, it is not conforming to anything
>>useful at all, since nobody would argue that it is useful programming
>>practice to ever do such a thing on purpose (I hope?).
>
>This particular example is done all the time in handling recursive data
>structures.
What do I mean by that? [I do not know how to reply by private mail--student
driver.]
A simple example is reversing a singly linked list and, just to make it
interesting, inserting the list ordinal:
p := nil; q := first_element; n := 1;
while q isnt nil
do
r := q.link; -- r and q.link are variables pointing at the location.
q.link := p; -- p and q.link are now pointing at the same location.
p := q; -- now p and q.
p.ordinal := n; -- as a sideeffect, also modifies q.ordinal.
q := r; -- now r and q.
n +:= 1
od
More information about the Comp.lang.c
mailing list