RE: Attribute destructor function and C++ destructors

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

 



Hi Eljay,

Thankyou for the reply.

> My first recommendation is, if possible, never ever ever ever ever 
> ever ever rely on "stuff that happens before main()", and "stuff 
> that happens after main()".  Put explicit initialization in main 
> using RAII.  Life will be better.

I'm not sure what RAII is, will have to look it up.  However the
initialisation/finalisation I wanted to happen automatically on
shared library load/removal.

> Are the globals in the same translation unit (i.e., static 
> globals)?  If they are, they are slightly better behaved than if 
> the statics are being used across translation units.

They are static and in the same execution scope.  They are also not
passed as pointers outside that scope.  Ignoring specific syntax
the code in question basically amounts to:

static std:string test;

foo_init () << attribute constructor
{
    test = "hello";
}

foo_fini () << attribute destructor
{
    printf ("%s\n", test.c_str()); <<< invalid on 4.1.1
}

> If the static globals are in the same translation unit, where you 
> place them in the translation unit determines their OoC and LIFO 
> OoD.  If they do not have external linkage (extern globals), then 
> you can rely on their OoC.

Ok.  Normally I'm used to the listed first, created first/destructed last
approach, which I believe should make the above correct.  How would
you change order correctly between C++ destructors and an attribute
destructor function?

> If you are still running into problems, consider using the Nifty 
> Counter pattern (aka Schwarz counter), which is what the I/O 
> Streams use:
> 
> http://www-d0.fnal.gov/KAI/doc/tutorials/static_initialization.html

I'll take a look, thankyou.

Simon


-- 

Search for products and services at: 
http://search.mail.com



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux