Odd behavior with a struct {} constructor

I cannot understand why ROOT command line behaves like that:

If I access a member via the instantiated struct, it returns the value of another member. If I access the same member via a pointer (another struct created with the new keyword, or even for the same struct as before) it return the correct value.

In the following code, member x should be (const double) -3.0, and is correct whichever way I use, and member z should be (const double) 0.0, but it returns either -3.0 when accessed with the dot, and 0.0 when accessed with the ->

For clarity I leave also the responses provided by root.

    struct vertex {
        const double x;
        const double y;
        const double z;
        vertex(double x, double y, double z) : x(x), y(y), z(z) {};

        vertex operator-(const vertex& other) const;

root [0] struct vertex {
root (cont'ed, cancel with .@) [1]        const double x;
root (cont'ed, cancel with .@) [2]        const double y;
root (cont'ed, cancel with .@) [3]        const double z;
root (cont'ed, cancel with .@) [4]        vertex(double x, double y, double z): x(x), y(y), z(z) {};
root (cont'ed, cancel with .@) [5]
root (cont'ed, cancel with .@) [5]        vertex operator-(const vertex& other) const;
root (cont'ed, cancel with .@) [6]    };

root [7] vertex a(-3, -3, 0);
root [9] a.x
(const double) -3.0000000  - OK
root [10] a.y
(const double) -3.0000000 - OK
root [8] a.z
(const double) -3.0000000 - NO!!! Should be zero

//Same results with root [11] vertex b = {-3.0, -3.0, 0.0};


root [15] vertex *c = new vertex(-3, -3, 0);
root [17] c->x
(const double) -3.0000000 - OK
root [19] c->y
(const double) -3.0000000 - OK
root [20] c->z
(const double) 0.00000000 - OK

but even odder:

root [23] a.z
(const double) -3.0000000 - NO!!!
root [22] (&a)->z
(const double) 0.00000000 - BUT THIS IS CORRECT!!!

Windows 10, installed from the binaries
Welcome to ROOT 6.18/04 https://root.cern |
© 1995-2019, The ROOT Team |
Built for win32 on Sep 11 2019, 15:38:23 |
From tags/v6-18-04@v6-18-04___


This looks like a bug on Windows (it works fine on Linux). Thanks for reporting it, I just created a Jira issue

Cheers, Bertrand.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.