Boost logo

Boost :

From: james.jones_at_[hidden]
Date: 2006-09-22 16:23:18


From: Marcus Lindblom <macke_at_[hidden]>
> Martin Bonner wrote:
> > A more serious problem is if you start mixing usages. A compiler is
> > quite likely to assume that assignments through the result of the index
> > operator don't affect .y or .z, and optimize on that basis.
>
> Why should it? The offset to memory will be the same, so it should treat
> it as access to the same memory location, if it optimizes well in the
> backend ('assembly' AST).

vector3d v;
v.y = 4.0;
v[1] = 5.0; // only touches v.x!!
cout << v.y;

Since v.x is assigned to but never used, the compiler might optimize away the assignment.

In practice, compilers typically don't do this optimization when pointers are present, precisely because hackers^W programmers do stuff like this. I certainly wouldn't want to *assume* this for my compiler, though.

-
James Jones Administrative Data Mgmt.
Webmaster 375 Raritan Center Pkwy, Suite A
Data Architect Edison, NJ 08837


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk