Egbert Molenkamp said:
Only predefined operators can be overloaded.
It's very interesting to ask why this should be so.
Infix operators may have (or lack) many properties that
the compiler needs to know about:
associativity (left, right, none?)
commutativity (needed when optimising a syntax tree)
distributivity (also important for some optimisations)
binding precedence
When you permit unary operators to be either prefix or
postfix, like ++ in C, then things get even more complicated.
Consequently it's very difficult to design a language in which
you can freely define your own operators. When you overload
the VHDL built-in operators, all their other properties, as
mentioned above, remain unchanged - they are built in to the
compiler.
Algol-68 allowed arbitrary operator definition - it was one
of the most complicated features of the language. Does
anyone know of any other languages that offer it?
Be happy with regular procedures. After all, when you want
s++
it's not outrageously hard to write instead
incr(s)
using your own procedure incr().
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services
Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail: (e-mail address removed)
Fax: +44 (0)1425 471573 Web:
http://www.doulos.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.