|Re: [eigen] operator overloading vs expression templates, and the need to return references|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] operator overloading vs expression templates, and the need to return references
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Fri, 11 Sep 2009 21:26:18 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=6W44jRkjXXZhKF5waCfZ9SzaX0glgl/uoyEWVNTFY3k=; b=ftfedphX/X/YAFVGgeFt+OQz8i6jQQgOPj5Mqd9RZJOEdNK+Q/shs2BGJR/2EPitZc txHztkz0cNH3wsXYVjFzEje69u3LxZjCuX0gFB0ACEuy7kEqQWPQPJ5radSc+5FvNZ2o HBGSgCpveRRjJmUSu9tR45Xuucx25XYZp4w5A=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ejXFX6YekCzSflidp8ec4VZoY+vEanjC3ltt5UnOBFzOmiP730QLFFm2GXao6iHat7 TRagv/WMYylwgRW8hLcMYgGGUFS5B9UwxyvUwiyJmRgzbB1NJ+L6fBhxW7EuEq0Q1kAt pkDDw4COtqTVR2D38WYdy7Ifps75kaWQrhx6I=
here vector8s is supposed to fit into a single SSE register so you
should simply return it by value, just like you would do with a float
or int or whatever scalar type.
On Fri, Sep 11, 2009 at 8:30 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
> 2009/9/11 Rohit Garg <rpg.314@xxxxxxxxx>:
>> Back to my previous question, can somebody explain to me on how to
>> suppress those warnings in a meaningful way?
> You mean with your function returning a reference to a local temporary,
> inline vector8s& operator+(vector8s &other)
> vector8s temp;
> return temp;
> There's no good way to get rid of that warning, because there issue
> here is really serious! I've never heard of a way to return a
> reference to local variable in a function, I don't see how that could
> work. In C++1x, they are introducing rvalue references, and if I
> understand correctly that's exactly what you want. But your above code
> doesn't look safe at all to me: "temp" lives on the stack, when the
> function returns the stack pointer is decremented and the content of
> "temp" may then be overwritten. Unless there is something that I don't
> understand : that happens frequently too!
> In eigen and more generally with expression templates, the solution is
> to return by value, but return very lightweight objects (these are the
> "expression objects") instead of returning plain matrices.