From 1079747066426693659
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,de99e5c46dfe5a28
X-Google-Attributes: gidf78e5,public
From: "Ross Smith" <ross.s@ihug.co.nz>
Subject: Re: Multiple declarations in for loop?
Date: 1998/05/20
Message-ID: <6jsv8o$q03$1@newsource.ihug.co.nz>#1/1
X-Deja-AN: 354870532
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
Content-Transfer-Encoding: 7bit
References: <35608CBB.2571@lehman.com>
X-Original-Date: Wed, 20 May 1998 09:58:35 +1200
Content-Type: text/plain; charset="iso-8859-1"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: The Internet Group
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANWJ9PuEDnX0m9pzZAQExYgF/YcsugsddlAQtgOEZieHdTnFHM/Lq6Wsn nFMd03dR6/7rrxuGXC1//lTPcwJH1Ag2 =ie2a
Mime-Version: 1.0
Newsgroups: comp.std.c++


Cristian Georgescu wrote in message <35608CBB.2571@lehman.com>...
>Does the language allow the definition of multiple variables in a for
>loop?
>
>F.I.: the compiler I am using (VC5.3) is accepting the following:
>
>int j=0;
>for (int i=0; i<10,j<10; i++, j++)
>{
> //...
>}

It accepts it, but I bet it isn't doing what you think it is. The comma
operator means "evaluate the LHS, discard the result, then evaluate the
RHS". Your termination clause, "i<10,j<10", is equivalent to plain
"j<10". I'm surprised the compiler didn't give a warning about an unsed
expression. (In the above loop the result is the same because both
variables are being incremented together, unless there's code inside the
loop that changes i or j.)

>but does not accept the following:
>
>for (int i=0, int j=0; i<10,j<10; i++, j++)
>{
> //...
>}
>
>Is this in the standard or it is just a compiler bug?

It's standard. You can't join declarations with the comma operator.

--
Ross Smith ................................... mailto:ross.s@ihug.co.nz
.............. The Internet Group, Auckland, New Zealand ..............
  "Remember when we told you there was no future? Well, this is it."
                                                        -- Blank Reg
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



