[LC++]can't seem to use reference

Mark Phillips mark at austrics.com.au
Thu Feb 21 10:26:35 UTC 2002


Carlo Wood wrote:
> 
> On Wed, Feb 20, 2002 at 12:25:42PM +1030, Mark Phillips wrote:
> > Or actually, I could do:
> >
> > for (largeStructTy const* lsPr=&largeStructList[0];
> >     lsPr<&largeStructList[N];) {
> >   largeStructTy const& ls(*lsPr);
> >   ++lsPr;
> >   largeStructTy const& nextLs(*lsPr);
> >   // do stuff involving the reading of ls and nextLs
> >   // ...
> > }
> >
> > How would the compiler deal with this?  nextLs and lsPr could
> > be the same register, but would the compiler do this?
> 
> That won't work, you'd have just one variable,
> ls and nextLs are the same!

I realize you need at least two registers.  But one could hold lsPr
and nextLs (equivalent) and the other could hold ls.  The point is
that nextLs is only constructed late, and throughout the remainder
of the scope, lsPr and nextLs refer to the same thing.  But can
the compiler work this out?

Cheers,

Mark.



More information about the tuxCPProgramming mailing list