From c79b6ffe1fcf8c12005942a1268f79b7d6ecf700 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 20 Nov 2019 17:31:23 +0100 Subject: Add an explicit example for auto and re-evaluation --- doc/Pitfalls.dox | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/Pitfalls.dox b/doc/Pitfalls.dox index 18ced6ea7..6760ce6d2 100644 --- a/doc/Pitfalls.dox +++ b/doc/Pitfalls.dox @@ -40,7 +40,17 @@ for(...) { ... w = C * v; ...} In this example, the type of C is not a \c MatrixXd but an abstract expression representing a matrix product and storing references to \c A and \c B. Therefore, the product of \c A*B will be carried out multiple times, once per iteration of the for loop. -Moreover, if the coefficients of A or B change during the iteration, then C will evaluate to different values. +Moreover, if the coefficients of `A` or `B` change during the iteration, then `C` will evaluate to different values as in the following example: + +\code +MatrixXd A = ..., B = ...; +auto C = A*B; +MatrixXd R1 = C; +A = ...; +MatrixXd R2 = C; +\endcode +for which we end up with `R1` ≠ `R2`. + Here is another example leading to a segfault: \code -- cgit v1.2.3