Re: RFC: glocal - automatically freeing memory when it goes out of scope



On Thu, 05 Apr 2012 10:58:24 -0400 (EDT)
Alexander Larsson <alexl redhat com> wrote:
[snip]
> I might have been a bit sloppy with my words, but the following C++
> code, in a shared library:
> 
> MyClass my_object;
> 
> Needs to have the MyClass constructor for the static object my_object
> run before the main() function in your application. This is identical
> to attribute constructor (in fact, implementation wise thats how this
> works in C++).

Ah, I understand you.  And of course, if not in a shared library also.

(C++ programmers soon learn to avoid static initialization of objects in
namespace scope, except for the most trivial of uses, because the order
of initialization between translation units is unspecified.  I know gcc
makes priority specification available as a GNU extension for C++, but
that is only really useful in C++ if you don't link outside your own
code and stick to gcc, so lazy initialization is almost always better.)

Chris


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]