delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/13/17:06:46

From: horst DOT kraemer AT t-online DOT de (Horst Kraemer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: variable declaration in for-header fails??
Date: Thu, 13 Jan 2000 20:13:13 GMT
Organization: T-Online
Lines: 65
Message-ID: <387e27c9.16119163@news.btx.dtag.de>
References: <387d91d5 DOT 333064 AT news DOT netcologne DOT de>
Mime-Version: 1.0
X-Trace: news01.btx.dtag.de 947794293 15161 0306239354-0001 000113 20:11:33
X-Complaints-To: abuse AT t-online DOT de
X-Sender: 0306239354-0001 AT t-dialin DOT net
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Thu, 13 Jan 2000 10:42:55 GMT, karpfenteich AT gmx DOT de (Peter Karp)
wrote:

> This first way compiles flawlessly with version 2.03:
 
> #include <iostream>
> using namespace std;
 
> int main()
> {
>   int x;
>   for(x=1, cout << x , x++ ;x<=100; x++)
>     cout << ", " << x;
> 
>   cout << endl;
> 
>   return(0);
> }
 
Correct. 
 
> ------------
> but fails, when I define the counter inside the loop declaration:
> 
> #include <iostream>
> using namespace std;
 
> int main()
> {
>   for(int x=1, cout << x , x++ ;x<=100; x++)
>     cout << ", " << x;
> 
>   cout << endl;
> 
>   return(0);
> }
 
> BTW, Borland C++ 3.1 compiles this version without an error, while


This is a open lie ;-) Borland C++ 3.1 doesn't compile it for the same
reason as GNU C++ doesn't. 

And of course BCC++ 3.1 doesn't support the syntax <iostream> and
doesn't support 'namespace'. But even after changing this it doesn't
compile.


         int x=1, cout << x , x++ ;

is illegal. You cannot separate a declaration and an expression like
cout<<x by a comma.

You can use _either_ a declaration like int x=1; _or_ an expression
like

	x=1,...,....,...;


but you can't have both.


Regards
Horst

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019