Newsgroups: | comp.compilers |
From: | dmw9q@uvacs.cs.Virginia.EDU (David M. Warme) |
Keywords: | design, polymorphism |
Organization: | University of Virginia Computer Science Department |
References: | <9008310419.AA06194@karakorum.berkeley.edu> <4c98dcd0b.001a92c@caen.engin.umich.edu> |
Date: | Wed, 5 Sep 90 10:16:53 EDT |
In article <4c98dcd0b.001a92c@caen.engin.umich.edu> Mark Montague writes:
>So I imagine that every expression of the form
> myarray[index]
>is silently transformed into
> *(myarray+index)
>before the compiler even sees it. Even though it probably doesn't happen
>this way for most compilers, this fictional device lets me ignore questions
>of polymorphism and operator overloading in a non-object-oriented language
>such as C.
This does not remove polymorphism and/or overloading, it merely
transfers the burden onto + and *. The expansion you state is THE
DEFINITION of the operator. A C compiler I wrote does this during
parsing by building two parse-tree nodes (* and +) rather than a
single node for []. The only detail to consider is that the node used
for * in this case is a specially-flavored * that differs in only one
respect from the "normal" * node: error messages say "invalid
subscript", rather than "illegal indirection".
- Dave Warme
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.