|
From: Ioannis V. <no...@ho...> - 2002-08-07 06:35:52
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Teodorescu Cristian
> Sent: Wednesday, August 07, 2002 8:29 AM
> Cc: dev-cpp-users-list
> Subject: Re: [Dev-C++] iterating by 2
>=20
>=20
> Carlos Garc=EDa del Monte wrote:
>=20
> > It shall work if it compiles. But when I declare /i /like=20
> you, inside=20
> > a for statement, the compiler reports error due to an old fashioned=20
> > way to declare it, try to declare it before the for. But then that=20
> > error should have been reported.
>=20
> Be carfull of file extension like :
> a.c and a.cpp
> if in a i have
> for (int i=3D0;i<19;i++)
> {
> };
> if you save like a.c you are candidate for an error depends if the=20
> compiler takes or not .c file like .cpp
> but if you save like a.cpp your compiler always take this=20
> statement like=20
> cpp
Actually, only with the exception that you use some specific compiler
treatment switch, a .c file is considered as a C source code and .cpp as
C++ source code.
C & C++ are *different* languages.
In ANSI C++ 1998 standard the definition inside a for loop is legal (and
recommended). In general you can define variables where you first need
them.
In ANSI C 1990 standard you can only define variables at the beginning
of a scope only.=20
In ANSI C 1999 standard you can define variables as in C++, but the
language is messy.
Anyway when you code in C++ always use .cpp file.
Concerning C, most compilers support (at least by default) C90.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|