mpfrcpp-common
[Top][All Lists]
Advanced

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

[MPFRCPP] order of initialization of globals


From: Richard
Subject: [MPFRCPP] order of initialization of globals
Date: Sat, 04 Aug 2007 22:37:50 -0600

Hi,

I managed to get mpfrcpp compiled on Win32 under VS.NET 2005.

When I ran the tests and samples, there was a crash in the object
initialization code.  I tracked it down to an order of object creation
problem.

initialization.cpp contains code to initialize the global objects.

If the objects are constructed by the compiler in the order they
appear in the source, then mpfr::Neg is the first object to be
constructed.  Its initialized to a default constructed instance
of NegClass.

NegClass derives from NumericFunction.  NumericFunction's default
constructor calls Real::getParameters().getDefaultPrecision().

Real::getParameters() returns a reference to a GlobalParameters class.
The reference hasn't been initialized to anything yet, so you get a
null pointer error.

If the initialization of mpfr::Parameters and mpfr::Real::params_ is
moved to the start of initialization.cpp and executed first, then the
crash is avoided.

However, C++ doesn't guarantee the order of construction of static
objects between compilation units.  So I'm not sure if this approach
to initialization is the best one.

I can send a diff of the change I made if that would help.
-- 
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
      <http://www.xmission.com/~legalize/book/download/index.html>

        Legalize Adulthood! <http://blogs.xmission.com/legalize/>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]