Dear Vladimir, Thanks for sharing with us an effect of the language's darker side! On 08.11.19 21:57, Vladimir V. Kisil wrote:
#include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main() { for (int i=0; i < 2; ++i) (i==0? realsymbol("r") : symbol("s")).dbgprinttree();
return 0; }
My expectation would be that it first creates a realsymbol r and then a symbol s. However, the actual output of the programme is:
r (symbol) @0x7fff6e472700, serial=1, hash=0x1689b718, flags=0x6, domain=0 s (symbol) @0x7fff6e472700, serial=2, hash=0x1689b718, flags=0x6, domain=0
That is, in both cases the domain is 0 (complex) and r is not recognised as a real symbol.
Shall this be corrected or did I misunderstand the concept of (A? B : C) construct?
We can't correct this. The first and second expression and aren't of the same type. The compiler has to find the conditional operator's type in order to call dbgprinttree(). The standard (section 8.16.4 in [IEC14882:2017]) specifies that the compiler must try to find the common type by trying to convert the one into each other. Since realsymbol is derived from symbol, this works only one way and this determines the type of the conditional operator. Note that the code isn't doing a dynamic call. This changes when you wrap the symbols into an ex. Many people recommend avoiding the conditional operator for a variety of reasons. -richy. -- Richard B. Kreckel <https://in.terlu.de/~kreckel/>