|
From: Luigi B. <lui...@gm...> - 2009-11-13 11:50:50
|
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 |