This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization/clarity coding : what is gcc able to do for me ?
Nick NoSpam <nicknospam@optonline.net> writes:
> On Fri, 2005-01-14 at 11:25 +0100, Pierre Chatelier wrote:
>
>> vector<int> v(1000);
>> for(int i=0 ; i<v.size() ; ++i)
>> v[i] = i;
>
> 2. Can the compiler optimize the size() call away (after calling it
> once)?
No, since it might have side effects. However, in this case the
compiler knows the definition of size() and can see it has no side
effects. Therefore, it can optimize out the calculation, except in the
case of vector<char>, where the optimizer has to assume the change of
v[i] might clobber members of the vector<char> struct.
--
Falk