A proposal

Richard B. Kreckel kreckel at ThEP.Physik.Uni-Mainz.DE
Wed Sep 15 22:05:37 CEST 1999


I would like to have some comments from you about a proposal about
constants:

In order to forbid insane code like this one in GiNaC:
EulerGamma = Pi;
cout << EulerGamma << endl;   // prints 3.14...
all objects of class constant need to be declared const (which is the
case for built-in constants). While the copy constructor for constants is
sane (because when you declare constant EulerGamma(Pi); this is a new
constant with local scope) the above case is not.  One could override
constant::operator= but there are other cases.  E.g. I wanted to override
constant::subs() to return *this but while this seemlingly worked for the
checks it caused basic's virtual table to be overridden with garbage (and
then executed, which caused a SEGV beeing raised) by the xloops check.  I
do not have any clue why this happens. Also, I had to change symbol::subs
to be somewhat more flexible.  

The whole trouble is IMHO caused by the fact that symbol is currently
partly caring for its derived class constant.  Can't we just eliminate
class constant and declare global symbols like Pi, EulerGamma and the like
and assign them an evalf()-function similar to how expressions may be
assigned to symbols?  Then just declare those special symbols const and
that's it?

I haven't tried it, just wanted to hear your comments and sleep a night
before doing something, maybe it's rubbish!

Cheers
    -rbk.
-- 
Richard Kreckel
<Richard.Kreckel at Uni-Mainz.DE>
<http://wwwthep.physik.uni-mainz.de/~kreckel/>





More information about the GiNaC-devel mailing list