On Wed, Aug 12, 2015 at 4:09 PM, Dan Kegel <d...@kegel.com> wrote:
> On Wed, Aug 12, 2015 at 12:58 PM, Jeffrey Walton <noloa...@gmail.com> wrote:
>> The C++ object that uses it is in another translation unit, and it has
>> a init_pritority attribute.
>
> File-scope or static C++ objects are the spawn of the devil.
> There is no reliable or portable way to control initialization order,
> even with init_priority,   See e.g.
> http://stackoverflow.com/questions/3371968/attribute-init-priorityx-in-gcc

I agree about the evil-ness of file scope C++ objects. Its been a
chronic pain point.

Even static locals have problems. I once had a logger class with an accessor:

   Logger& GetLogger() {
        static Logger s_logger;
        return s_logger;
    }

Yep, logger crashed on program shutdown because the logger was using
another static local that was declared in another translation unit and
destroyed too soon.

The GCC folks told me to use init_priority for these issues. See
"Method to specify initialization order across translation units?"
(https://gcc.gnu.org/ml/gcc-help/2015-08/msg00025.html).

Jeff

------------------------------------------------------------------------------
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to