Article View: comp.std.c++
Article #3738Re: Two questions about declarations in condit
From: scott douglass
Date: Tue, 19 Mar 1996 17:44
Date: Tue, 19 Mar 1996 17:44
32 lines
2193 bytes
2193 bytes
In article <4ikkbu$b5u@engnews1.Eng.Sun.COM>, clamage@Eng.Sun.COM wrote:
: In article 1403961511110001@193.131.176.202, sdouglas@armltd.co.uk
: (scott douglass) writes:
: >[...]
: >Bonus question: why does the grammer allow only the '=
: >assignment-expression' form:
:
: >[grammar to allow 'while (T t(i)) { /* ... */]
:
: I think the general case could lead to ambiguities in parsing. If a
: function call can possibly be interpreted as a variable definition, then
: it is a variable definition. That could lead to unexpected behavior
: which would be difficult to track down.
:
: You can always write the same thing with "=" notation:
: while( T t = T(i) ) { ... }
: This rewrite is not guaranteed to be as efficient, but most compilers
: do optimize away the extra copy.
It is not the same if the copy-constructor for T is private (say, as part
of preventing copying of Ts) and the constructor from the type of 'i' is
public, as is the case in at least one class I have. Then only the 'T
t(i)' form is legal.
--scott
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<sdouglas-1903961328250001@193.131.176.202>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernReferences:
<sdouglas-1403961511110001@193.131.176.202> <4ikkbu$b5u@engnews1.Eng.Sun.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: sdouglas@armltd.co.uk (scott douglass) Newsgroups: comp.std.c++ Subject: Re: Two questions about declarations in condit Date: 19 Mar 1996 09:44:41 PST Organization: Apple Computer, Inc. Approved: austern@isolde.mti.sgi.com Message-ID: <sdouglas-1903961328250001@193.131.176.202> References: <sdouglas-1403961511110001@193.131.176.202> <4ikkbu$b5u@engnews1.Eng.Sun.COM> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: Tue, 19 Mar 1996 13:28:24 +0000 X-Newsreader: Yet Another NewsWatcher 2.0.2 X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMU7ynky4NqrwXLNJAQHR3QIAnH9ds+gFv4doPimMkHgeiwzwUdTWT33y hUZBBoUKEvUpXMYeN1JaT8alNrrfOx8FcWc+15soQW8EUM+f0qLsvQ== =3qbt Originator: austern@isolde.mti.sgi.com