Topic: for loops and searching the PDF standard
Author: smeyers@aristeia.com (Scott Meyers)
Date: 1999/02/18 Raw View
Okay, clearly I'm too stupid to figure out how to search the PDF version of
the standard. I happen to want to check that both of the following
syntactic forms are legit in the for-init-statement part of a for loop:
for (T variable = initVal; ...)
for (T variable(initVal); ...)
I know the first is valid, but I'm not 100% sure about the second. After
all, the "=" is required for default parameter values.
Page 121 of the PDF (numbered page 97 -- I *hate* PDF) notes that a
for-init-statement expands to either an expression-statement or a
simple-declaration. So I tried to search for "simple-declaration", but
Acrobat Reader can't find any matches. Sigh.
Questions:
1. How do I search for "simple-declaration" using Acrobat Reader?
2. Is the "T variable(initVal)" syntax legit in for loops?
Thanks,
Scott
--
Scott Meyers, Ph.D. smeyers@aristeia.com
Software Development Consultant http://www.aristeia.com/
Visit http://meyerscd.awl.com/ to demo the Effective C++ CD
---
[ 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: miker3@ix.netcom.com (Michael Rubenstein)
Date: 1999/02/18 Raw View
On 18 Feb 99 06:48:24 GMT, smeyers@aristeia.com (Scott Meyers) wrote:
>Okay, clearly I'm too stupid to figure out how to search the PDF version=
of
>the standard. I happen to want to check that both of the following
>syntactic forms are legit in the for-init-statement part of a for loop:
>
> for (T variable =3D initVal; ...)=20
> for (T variable(initVal); ...)
>
>I know the first is valid, but I'm not 100% sure about the second. Afte=
r
>all, the "=3D" is required for default parameter values. =20
>
>Page 121 of the PDF (numbered page 97 -- I *hate* PDF) notes that a
>for-init-statement expands to either an expression-statement or a
>simple-declaration. So I tried to search for "simple-declaration", but
>Acrobat Reader can't find any matches. Sigh.
>
>Questions:
> 1. How do I search for "simple-declaration" using Acrobat Reader?
> 2. Is the "T variable(initVal)" syntax legit in for loops?
1. This appears to be the old problem of handling various dashes in
printed material. The hyphen, minus sign, em dash, en dash (and a few
other similar characters) have different representations in printed
material. The PDF viewer apparently isn't intelligent enough to
search for any of them when you search for "simple-declaration" and
the hyphen in "simple-declaration" is apparently not the translation
of the ASCII "-" character. I don't have a solution.
2. simple-declaration occurs in the productions at the beginning of 7
as
simple-declaration:
decl-specifier-seq(opt) init-declarator-list(opt) ;
Near the beginning of 8 we find the productions
init=ADdeclarator=ADlist:
init=ADdeclarator=20
init=ADdeclarator=ADlist , init=ADdeclarator=20
init=ADdeclarator:=20
declarator initializer(opt)
Near the beginning of 8.5 we find the productions
initializer:=20
=3D initializer=ADclause=20
(expression=ADlist)
Hence the "T variable(initVal)" syntax is legit in for loops.
--
Michael M Rubenstein
---
[ 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: anatoli@my-dejanews.com
Date: 1999/02/18 Raw View
In article <MPG.1135172be7bbadc6989689@news.teleport.com>,
smeyers@aristeia.com (Scott Meyers) wrote:
[snip]
> Questions:
> 1. How do I search for "simple-declaration" using Acrobat Reader?
Enter "simple declaration". Acrobat Reader will search for
"simple.*declaration" or something like that.
> 2. Is the "T variable(initVal)" syntax legit in for loops?
It is according to CD2. I don't have a copy of the IS, shame on me.
simple declaration:
decl specifier seq_opt init declarator list_opt ;
init declarator list:
init declarator
init declarator list , init declarator
init declarator:
declarator initializer_opt
initializer:
= initializer clause
( expression list )
[I use CD2, so I can cut-and-paste.]
--
Regards
Anatoli (anatoli at ptc dot com) opinions aren't
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ 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: James Kuyper <kuyper@wizard.net>
Date: 1999/02/18 Raw View
Scott Meyers wrote:
>
> Okay, clearly I'm too stupid to figure out how to search the PDF version of
> the standard. I happen to want to check that both of the following
> syntactic forms are legit in the for-init-statement part of a for loop:
>
> for (T variable = initVal; ...)
> for (T variable(initVal); ...)
>
> I know the first is valid, but I'm not 100% sure about the second. After
> all, the "=" is required for default parameter values.
>
> Page 121 of the PDF (numbered page 97 -- I *hate* PDF) notes that a
> for-init-statement expands to either an expression-statement or a
> simple-declaration. So I tried to search for "simple-declaration", but
> Acrobat Reader can't find any matches. Sigh.
>
> Questions:
> 1. How do I search for "simple-declaration" using Acrobat Reader?
Replace the '-' with a space. The way Acrobat Reader handles searches
seems to mishandle many characters that are neither letters nor digits.
Incidentally, this makes searching for C/C++ code fragments virtually
impossible.
> 2. Is the "T variable(initVal)" syntax legit in for loops?
My copy is at home, so I can't check, but I'd expect it to qualify as a
simple-declaration.
[ 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: "Andrei Alexandrescu" <alexandrescua@micromodeling.com>
Date: 1999/02/18 Raw View
Michael Rubenstein wrote in message
<36cf0311.1091766987@nntp.ix.netcom.com>...
[snip]
Okay, same question for initializing references. MSVC 5 and 6 reject the
following code:
int i;
int & j(i);
Is this code illegal? If yes, why?
Andrei
---
[ 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: 1999/02/19 Raw View
In article <36cc36a1.0@10.1.1.65>, Andrei Alexandrescu <alexandrescua@mi
cromodeling.com> writes
>Okay, same question for initializing references. MSVC 5 and 6 reject the
>following code:
>
>int i;
>int & j(i);
>
>Is this code illegal? If yes, why?
That question is backwards. The question should be 'Is this code legal,
if so justify from the grammar'. Without looking I think the answer
should be that it is illegal. Now the onus is to prove me wrong.
Francis Glassborow Chair of 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: miker3@ix.netcom.com (Michael Rubenstein)
Date: 1999/02/19 Raw View
On 18 Feb 99 20:01:54 GMT, "Andrei Alexandrescu"
<alexandrescua@micromodeling.com> wrote:
>Michael Rubenstein wrote in message
><36cf0311.1091766987@nntp.ix.netcom.com>...
>[snip]
>
>Okay, same question for initializing references. MSVC 5 and 6 reject the
>following code:
>
>int i;
>int & j(i);
>
>Is this code illegal? If yes, why?
The code is legal using the same productions I cited. This is a bug
in VC++.
--
Michael M Rubenstein
---
[ 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: "Matt Seitz" <mseitz@meridian-data.com>
Date: 1999/02/20 Raw View
Francis Glassborow wrote in message ...
>>Is this code illegal? If yes, why?
I see two possible meanings to the question "Why is this code illegal?"
1. "Where in the Standard does it say this code is illegal?"
2. "Why did the commitee choose to make this code illegal?"
It's not clear to me which of these meanings the author intended.
>That question is backwards. The question should be 'Is this code legal,
>if so justify from the grammar'.
This is a good answer to the first meaning of "Why is this code illegal?"
If the Standard doesn't say that something is allowed, then it is forbidden.
Therfore, one's goal should be to find where something is allowed by the
Standard, and then make sure there isn't some other rule that prohibits the
particular case in question. However, this response doesn't answer the
second meaning, that of asking the Commitee's rationale for choosing to make
the code legal or illegal.
[ 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 ]