Topic: The <if statement>
Author: "Michael Kochetkov" <mkochetk@trustworks.commm>
Date: 2000/04/30 Raw View
Hi, all,
why do many compilers say that it is ill-formed? I would appreciate the
answer with a proper paragraph of the standard (I have failed to find one).
int
main()
{
if (int i (1)) {}
return 0;
}
Thank you in advance,
Michael Kochetkov.
---
[ 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 ]
Author: "pm" <pm@NOSPAM.net>
Date: 2000/04/30 Raw View
"Michael Kochetkov" <mkochetk@trustworks.commm> wrote in message
news:390b0057@news.telekom.ru...
> Hi, all,
> why do many compilers say that it is ill-formed? I would appreciate the
> answer with a proper paragraph of the standard (I have failed to find
one).
> int
> main()
> {
> if (int i (1)) {}
> return 0;
> }
>
> Thank you in advance,
> Michael Kochetkov.
>
>
> ---
> [ 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 ]
>
[stmt.select] 6.4 Selection statements
1 Selection statements choose one of several flows of control.
selection -statement:
if ( condition ) statement
if ( condition ) statement else statement
switch ( condition ) statement
condition:
expression
type -specifier- seq-declarator = assignment- expression
^^^^^
Your example is not in the C++ grammar. The token = must follow
a type-specifier-seq-declarator.
if (int i = (1)) {} // OK
---
[ 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 ]
Author: Dennis Yelle <dennis51@jps.net>
Date: 2000/04/30 Raw View
pm wrote:
>=20
> "Michael Kochetkov" <mkochetk@trustworks.commm> wrote in message
> news:390b0057@news.telekom.ru...
> > Hi, all,
> > why do many compilers say that it is ill-formed? I would appreciate t=
he
> > answer with a proper paragraph of the standard (I have failed to find
> one).
> > int
> > main()
> > {
> > if (int i (1)) {}
> > return 0;
> > }
> >
> > Thank you in advance,
> > Michael Kochetkov.
>=20
> [stmt.select] 6.4 Selection statements
>=20
> 1 Selection statements choose one of several flows of control.
>=20
> selection=AD-statement:
>=20
> if ( condition ) statement
> if ( condition ) statement else statement
>=20
> switch ( condition ) statement
>=20
> condition:
>=20
> expression
> type=AD-specifier-=ADseq-declarator =3D assignment-=ADexpressio=
n
> ^^^^^
>=20
> Your example is not in the C++ grammar. The token =3D must follow
> a type-specifier-seq-declarator.
>=20
> if (int i =3D (1)) {} // OK
Was this:
if (int i(1) )=20
left out of the C++ grammar on purpose, or was it just an oversight?
If on purpose, why was it left out?
Dennis Yelle
---
[ 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 ]
Author: jpotter@falcon.lhup.edu (John Potter)
Date: 2000/04/30 Raw View
On Sun, 30 Apr 2000 02:21:25 CST, "Michael Kochetkov"
<mkochetk@trustworks.commm> wrote:
> why do many compilers say that it is ill-formed? I would appreciate the
> answer with a proper paragraph of the standard (I have failed to find one).
See 6.4/1 grammar for condition.
> int
> main()
> {
> if (int i (1)) {}
> return 0;
> }
It is ill-formed. The condition of if, switch, while and for includes
the '=' symbol. I seem to remember that the for initializer was
originally the same, but that is no longer true.
John
---
[ 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 ]
Author: "Michael Kochetkov" <mkochetk@trustworks.commm>
Date: 2000/05/01 Raw View
Thank you all for your replies. I have not noticed the elephant.
With regards,
Michael Kochetkov.
"Michael Kochetkov" <mkochetk@trustworks.commm> wrote in message
news:390b0057@news.telekom.ru...
> Hi, all,
> why do many compilers say that it is ill-formed? I would appreciate the
> answer with a proper paragraph of the standard (I have failed to find
one).
> int
> main()
> {
> if (int i (1)) {}
> return 0;
> }
>
> Thank you in advance,
> Michael Kochetkov.
>
>
> ---
> [ 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 ]
>
---
[ 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 ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/05/01 Raw View
In article <7NJO4.17170$fV1.122416@news1.atl>, pm <pm@NOSPAM.net> writes
>Your example is not in the C++ grammar. The token = must follow
>a type-specifier-seq-declarator.
>
>if (int i = (1)) {} // OK
I hope that you are mistaken because function type initialisation is
quite common in this context and avoids certain problems that assignment
style has (not least the effect of explicit qualified and or private
copy ctors)
Francis Glassborow Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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 ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/05/01 Raw View
In article <390b495d.35969075@news.csrlink.net>, John Potter
<jpotter@falcon.lhup.edu> writes
>> int
>> main()
>> {
>> if (int i (1)) {}
>> return 0;
>> }
>
>
>It is ill-formed. The condition of if, switch, while and for includes
>the '=' symbol. I seem to remember that the for initializer was
>originally the same, but that is no longer true.
I think that is a 'de facto' default if not a 'de jure' one. The two
forms of intialisation are semantically different.
Francis Glassborow Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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 ]