Boost logo

Boost Users :

From: Gustavo Scotti (gscotti_at_[hidden])
Date: 2008-01-28 11:52:33


James,

I don't know if that would help, but experience told me not to use
global objects. The reason is quite simple: compiler decides creation
order, putting its destructor on atexit. This falls out to unexpected
behavior related to interdependency between globals. You may try:

const boost::path& get_test() {
        static boost::path g_test( "/usr/bin/whatever" );
         return g_test;
}

you can even:

#define test g_test()

to make your switch more "friendly".

Anyway, there's nothing wrong with globals. All that matters is its
creation/destruction order when dependency exist. But that's the main
reason globals exists, right?
You may try to look for some singleton design pattern implementation.
It may help you either. I thought I've seen it on boost.

Regards,

GS

On Jan 28, 2008, at 2:06 PM, Hughes, James wrote:

> Hello all,
>
> We have had problems with boost::path when used as a const global
> variable, using gcc on ARM Linux. Example code (typed in the the email
> so probably missing code, but this is the basic premise)
>
>
> #include <boost/filesystem/path.hhp>
>
> const boost::path test = "/usr/bin/whatever";
>
> main()
> {
> //something
> }
>
>
> This crashes prior to getting to main, obviously whilst the path is
> being set up during initialisation.
>
> Is this a known problem? Is there a way round it? Have we
> misunderstood
> something important?
>
> Path works fine elsewhere, its only when some sort of initialisation
> code is called that it goes pear shaped.
>
> James
>
>
>
>
>
>
> This message (including any attachments) contains confidential
> and/or proprietary information intended only for the addressee.
> Any unauthorized disclosure, copying, distribution or reliance on
> the contents of this information is strictly prohibited and may
> constitute a violation of law. If you are not the intended
> recipient, please notify the sender immediately by responding to
> this e-mail, and delete the message from your system. If you
> have any questions about this e-mail please notify the sender
> immediately.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net