This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Declarations in a for loop


On Wed, 18 May 2005 11:06:23 -0500
Eljay Love-Jensen <eljay@adobe.com> wrote:

> Hi Fred,
> 
> >However, if I declare index and doublesIter before the for, then all
> >works fine.  Is that a bug?
> 
> Nope, not a bug.  What you have here is a case of bad C++ code.
> 
> #1
> int x, y; // This is good.
> 
> #2
> int x; std::vector<double>::iterator y; // This is good.
> 
> #3
> std::vector<double>::iterator x, y; // This is good.
> 
> #4
> int x, std::vector<double>::iterator y; // This is not good.
> 
> You can't put #2 in a for-loop initialization expression (since it's
> two expressions).
> 
> #1 and #3 won't do what you want.
> 
> #4 isn't C++, whether inside or outside of a for-loop initialization
> expression..

But you can have:

for (int i, int j; ...)

Seen examples of that in Josuttis' OO programming in C++ (while I was
verifying whether I could have several declerations in the for).

Fred


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]