Re: [eigen] operator overloading vs expression templates, and the need to return references |
[ Thread Index |
Date 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: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Fri, 11 Sep 2009 14:30:30 -0400
- 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; bh=ChDFI8eIkGHL6IUuzW9TSYzET0hTKMr+TDkamLAktrw=; b=Xjr3u8VNQ2ETdZCg/lRnjwbE+1Y/MgOVgbfWbR07GxJQ0STGY9n88gZ/lpdwAdgmcp jsTWpgugaPQlS8qptjABPTj24otRwgVrNRteuPZ3TS486HtMR1ZS7pgFUMAp7cJTbgmD SzbY3zPE28YB6kGIK1JNxikdqlmashYKvfUtE=
- 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; b=cDpZ5eYKzsMJ3SLCfQRFLMQmBduHJBn2DqUU+C7HkUeJcx5KdvaJCm//ugfu5rEIAH hA0vKHPf/1GGGMZY59Sdbsw/42DsF9HRhACQfW172QiqDeWC1voZKNE3YskkRY3mXaKC IvMR8mX3UbsPpaeM1Wt2XFVZd45oUoz/a/Dxo=
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;
temp.data=_mm_add_epi16(data,other.data);
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.
Benoit