Posted by
Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/market-models-code-tp11949p11950.html
On Tue, 2009-11-10 at 14:07 +1100, Mark joshi wrote:
> as you'll have noticed I've been doing some fiddling with the market
> models code.
Mark,
just for future reference: when using gcc, the test suite was failing
hard (access violations and such.) It turns out that according to the C
++ standard, the valarray assignment operator is only required to work
when the two sides of the assignment have the same size (yes, one never
ends learning C++.) More details in the standard and at
<
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/b9ac323fd7f5578b/dba133d7b15e91e0?hl=en&ie=UTF-8>.
Therefore, when one writes
valarray<Foo> v1;
v1 = some_function();
where some_function returns a (presumably not empty) valarray, the
behavior is undefined (the above effectively occurs, for instance, when
a valarray data member is initialized in the constructor body.) Visual
C++ tries to help the average programmer and does what one would expect
(i.e., resize v1 and copy.) Instead, gcc silently ignore the assignment
so that v1 ends up still empty. You say it's kind of snob of gcc? My
reaction exactly. Well, my second reaction. The first involved a lot
of cursing.
Conclusion: I committed a few changes to keep the code portable.
Basically, one has to include a few valarray.resize() calls before
assignment. Unfortunately, we'll have to keep that in mind when we write
new valarray code.
Luigi
P.S. About the MarketModel example: please whistle in my general
direction when it's done, so I can backport it to the 1.0 branch.
Thanks.
--
I'd never join any club that would have the likes of me as a member.
-- Groucho Marx
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.
http://p.sf.net/sfu/bobj-july_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev