Supporting Structure Comparison
Jerry Leichter
leichter at yale-com.UUCP
Wed Oct 5 23:23:01 AEST 1983
One more general approach - which I won't either advocate or criticise, for
the moment - has been taken by some compilers (I saw it in some HP compiler):
You allow user-defined operator extensions. Thus, if a and b are of type
COMPLEX,
a + b
is compiled as if it was
SUM_COMPLEX_COMPLEX(a,b)
or some such thing.
To really make this usable for things like complex arithmetic, where I would
want the complex sum to be expanded in line, it should allow SUM_COMPLEX_COMPLEX
to be a macro. Unfortunately, this would be difficult because of the timing
of macro expansion and expression parsing; the compiler I saw just generated
a function call.
The big question involved in such an approach is: Can you keep it small and
simple enough to be understandable - and implementable! - while still making
it useful? As a quick example of the kind of problem you run into, if a is
as above, what should you make of:
a + 1
If this calls SUM_COMPLEX_int, you'll end up having to write a LOT of functions
just to get things off the ground; if it calls SUM_COMPLEX_COMPLEX, things will
get very confused.
-- Jerry
decvax!yale-comix!leichter leichter at yale
More information about the Comp.lang.c
mailing list