Topic: Why does this compile?
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/04/21 Raw View
Alexandre Oliva <oliva@dcc.unicamp.br> writes:
>Fergus Henderson writes:
>
>> A conforming compiler most not use semantic rules to resolve
>> syntactic ambiguities.
>
>What about the declaration of foo in:
>
>class A {};
>
>void bar() {
> auto A foo(A());
>}
>
>There's a syntactic ambiguity here (the declarator could be either a
>declarator-id followed by a parenthesized initializer or a
>direct-declarator followed by an formal argument list).
Right. In this case the syntax disambiguation rule in 8.2/1 says that
the latter interpretation is the correct one.
>However, the
>`auto' keyword does disambiguate the declaration, since it cannot be
>used in a function declaration (a semantic rule).
>
>Shouldn't a compiler, in this case, use a semantic rule in order to
>resolve a syntactic ambiguity?
No. The code above is ill-formed (because the syntax disambiguation rule
says that it must be interpreted as function declaration, rather than an
object declaration, and because `auto' cannot be used in a function
declaration) and so a conforming compiler must issue a diagnostic.
That is the status quo. If you're asking about the _rationale_ for the
status quo, that is a different question... but for starters, unless
you want a backtracking compiler that tries all possible alternatives,
then you have to draw the line somewhere, and the current place where
the line is drawn seems as at least as good as any other.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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
]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1997/04/20 Raw View
Fergus Henderson writes:
> A conforming compiler most not use semantic rules to resolve
> syntactic ambiguities.
What about the declaration of foo in:
class A {};
void bar() {
auto A foo(A());
}
There's a syntactic ambiguity here (the declarator could be either a
declarator-id followed by a parenthesized initializer or a
direct-declarator followed by an formal argument list). However, the
`auto' keyword does disambiguate the declaration, since it cannot be
used in a function declaration (a semantic rule).
Shouldn't a compiler, in this case, use a semantic rule in order to
resolve a syntactic ambiguity?
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
Universidade Estadual de Campinas, SP, Brasil
---
[ 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
]
Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/04/11 Raw View
fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes:
|> James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:
|>
|> >fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes:
|> >
|> >|> No they aren't. To get that, you would need to write
|> >|>
|> >|> int();
|> >|> float();
|> >|> B();
|> >|>
|> >|> In fact even that wouldn't work, because there is an ambiguity between
|> >|> declarations and expressions there which is resolved in favour of
|> >|> declarations.
|> >
|> >Really. I don't think that the above would be legal declarations. (I
|> >don't think that a vacuous declaration is legal. Have I missed
|> >something?)
|>
|> I meant that it wouldn't work as expressions.
|>
|> The above would not be legal declarations. They are disallowed by
|> 7[dcl.dcl]/3 in the DWP.
|>
|> So first up is ambiguity resolution, which says they are declarations,
|> and then 7[dcl.dcl]/3 kicks in, and so a diagnostic is required.
This is where I'm confused. If they cannot legally be declarations,
where is the ambiguity to resolve?
--
James Kanze home: kanze@gabi-soft.fr +33 (0)1 39 55 85 62
office: kanze@vx.cit.alcatel.fr +33 (0)1 69 63 14 54
GABI Software, Sarl., 22 rue Jacques-Lemercier, F-78000 Versailles France
-- Conseils en informatique industrielle --
---
[ 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
]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/04/14 Raw View
James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:
>fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes:
>
>|> >|> int();
>|>
>|> So first up is ambiguity resolution, which says they are declarations,
>|> and then 7[dcl.dcl]/3 kicks in, and so a diagnostic is required.
>
>This is where I'm confused. If they cannot legally be declarations,
>where is the ambiguity to resolve?
The rule that the are not well-formed declarations is a semantic rule.
But in order to apply semantic rules, you must first parse the syntax.
The syntax is ambiguous. The ambiguity must be resolved according to
the rules in 8.2 "Ambiguity Resolution". A conforming compiler most not
use semantic rules to resolve syntactic ambiguities.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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
]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/04/09 Raw View
James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:
>fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes:
>
>|> No they aren't. To get that, you would need to write
>|>
>|> int();
>|> float();
>|> B();
>|>
>|> In fact even that wouldn't work, because there is an ambiguity between
>|> declarations and expressions there which is resolved in favour of
>|> declarations.
>
>Really. I don't think that the above would be legal declarations. (I
>don't think that a vacuous declaration is legal. Have I missed
>something?)
I meant that it wouldn't work as expressions.
The above would not be legal declarations. They are disallowed by
7[dcl.dcl]/3 in the DWP.
So first up is ambiguity resolution, which says they are declarations,
and then 7[dcl.dcl]/3 kicks in, and so a diagnostic is required.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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
]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/04/10 Raw View
Christopher Eltschka <celtschk@physik.tu-muenchen.de> writes:
>Reed Mangino wrote:
>>
>> I was surprised that this was valid so I did this:
>>
>> void main(void)
>> {
>> int;
>> float;
>> B;
>> }
>>
>> The above compiles and runs fine.... These aren't definitions or
>> declarations (are they?).
>
>I don't really know what your compiler does, but I can imagine
>that it interprets it as definitions of int variables via the implicit
>int rule, so it might be equivalent to
>
>int main()
>{
> int int; // local int variable named "int" (hiding global int type)
> ::int float; // local int variable "float"
> ::int B; // local int variable "B"
> return 0;
>}
This is a nice theory, but it is not correct.
Keywords are reserved, you can't use a keyword as a variable name.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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
]
Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/04/10 Raw View
Christopher Eltschka <celtschk@physik.tu-muenchen.de> writes:
|> Reed Mangino wrote:
|> >
|> > While programming last night I had a typo that surprised me.
|> > I declared a class B and meant to create an instance:
|> > B b(5);
|> > But, instead (the typo) I typed:
|> > B;
|> >
|> > I compiled and ran without issue (except for the fact that
|> > I had no b! :)
|> >
|> > I was surprised that this was valid so I did this:
|> >
|> > void main(void)
|> > {
|> > int;
|> > float;
|> > B;
|> > }
|> >
|> > The above compiles and runs fine.... These aren't definitions or
|> > declarations (are they?).
|> >
|> > Thanks for your time!
|> > Reed
|>
|> I don't really know what your compiler does, but I can imagine
|> that it interprets it as definitions of int variables via the implicit
|> int rule,
First, C++ doesn't have the implicit int rule, at least not in this
case. (In fact, within a function, I don't think that this would have
worked in C, either.) Second, you can't declare variables with names
like "int" or "float" anyway.
--
James Kanze home: kanze@gabi-soft.fr +33 (0)1 39 55 85 62
office: kanze@vx.cit.alcatel.fr +33 (0)1 69 63 14 54
GABI Software, Sarl., 22 rue Jacques-Lemercier, F-78000 Versailles France
-- Conseils en informatique industrielle --
---
[ 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
]
Author: mangino@saturn.planet.net (Reed Mangino)
Date: 1997/04/01 Raw View
While programming last night I had a typo that surprised me.
I declared a class B and meant to create an instance:
B b(5);
But, instead (the typo) I typed:
B;
I compiled and ran without issue (except for the fact that
I had no b! :)
I was surprised that this was valid so I did this:
void main(void)
{
int;
float;
B;
}
The above compiles and runs fine.... These aren't definitions or
declarations (are they?).
Thanks for your time!
Reed
--
^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^^-__-^^
Reed R. Mangino | ** Dialogic Corporation **
manginor@dialogic.com | World leader in the design of
mangino@planet.net | computer telephony systems
-----------------------------------------------------------
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/04/01 Raw View
mangino@saturn.planet.net (Reed Mangino) writes:
>While programming last night I had a typo that surprised me.
>I declared a class B and meant to create an instance:
>B b(5);
>But, instead (the typo) I typed:
>B;
>
>I compiled and ran without issue (except for the fact that
>I had no b! :)
>
>I was surprised that this was valid so I did this:
>
>void main(void)
>{
> int;
> float;
> B;
>}
>
>The above compiles and runs fine.... These aren't definitions or
>declarations (are they?).
They are syntactically correct declarations according to the grammar,
but they are prohibited by semantic rules in 7[dcl.dcl]/3 in the draft
working paper. If your compiler doesn't complain about them (i.e issue
a diagnostic), then it doesn't conform to the DWP.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1997/04/01 Raw View
Reed Mangino writes:
> void main(void)
> {
> int;
> float;
> B;
> }
> The above compiles and runs fine.... These aren't definitions or
> declarations (are they?).
Your compiler is broken. The declarator list of a declaration is only
allowed to be empty only when declaring a class type or an enum type,
which is not the case.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
Universidade Estadual de Campinas, SP, Brasil
---
[ 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
]
Author: drew@qualcomm.com (Drew Eckhardt)
Date: 1997/04/01 Raw View
In article <5hrcd0$584@jupiter.planet.net>,
Reed Mangino <mangino@saturn.planet.net> wrote:
> int;
> float;
> B;
>The above compiles and runs fine.... These aren't definitions or
>declarations (are they?).
They're definitions for anonymous objects which have a lifetime
of the expression they're in.
Useful for doing things like
needs_a_B (B(x,y,z));
and smart pointers
return (auto_ptr<B> (new B (x,y,z)));
--
"Come to the edge, Life said. They said: We are afraid. Come to the edge,
Life said. They came. Life pushed them...and they flew." -Guillaume Apollinaire
Work: drew@Qualcomm.COM Play: drew@PoohSticks.ORG
Home Page: <a href="http://www.poohsticks.org/drew/">Home Page</a>
---
[ 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
]
Author: mangino@saturn.planet.net (Reed Mangino)
Date: 1997/04/01 Raw View
Alexandre Oliva (oliva@dcc.unicamp.br) wrote:
: Reed Mangino writes:
: > void main(void)
: > {
: > int;
: > float;
: > B;
: > }
: > The above compiles and runs fine.... These aren't definitions or
: > declarations (are they?).
: Your compiler is broken. The declarator list of a declaration is only
: allowed to be empty only when declaring a class type or an enum type,
: which is not the case.
Just FYI: I have tried the above using MSVC++ 4.0 & 5.0 - no warnings
whatsoever...
Thanks to all who replied!
Reed
--
^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^-__-^^^-__-^^
Reed R. Mangino | ** Dialogic Corporation **
manginor@dialogic.com | World leader in the design of
mangino@planet.net | computer telephony systems
-----------------------------------------------------------
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Eric Gindrup <gindrup@okway.okstate.edu>
Date: 1997/04/02 Raw View
Fergus Henderson wrote:
> If your compiler doesn't complain about them (i.e issue
> a diagnostic), then it doesn't conform to the DWP.
> -- Fergus Henderson <fjh@cs.mu.oz.au>
Of course, expecting any vendor to release a compiler conforming
to a standard with the words "draft" and "working" in the title
might be expecting a little much. :)
-- Eric Gindrup ! gindrup@okway.okstate.edu
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: secheeseman@nbtel.nb.ca (Silas Cheeseman)
Date: 1997/04/02 Raw View
On 01 Apr 97 16:20:27 GMT, mangino@saturn.planet.net (Reed Mangino)
wrote:
>While programming last night I had a typo that surprised me.
>I declared a class B and meant to create an instance:
>B b(5);
>But, instead (the typo) I typed:
>B;
>
>I compiled and ran without issue (except for the fact that
>I had no b! :)
>
>I was surprised that this was valid so I did this:
>
>void main(void)
>{
> int;
> float;
> B;
>}
>
>The above compiles and runs fine.... These aren't definitions or
>declarations (are they?).
Your code doesn't get past my Borland C++ 4.5 compiler.
---
[ 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
]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/04/02 Raw View
drew@qualcomm.com (Drew Eckhardt) writes:
>In article <5hrcd0$584@jupiter.planet.net>,
>Reed Mangino <mangino@saturn.planet.net> wrote:
>
>> int;
>> float;
>> B;
>
>>The above compiles and runs fine.... These aren't definitions or
>>declarations (are they?).
>
>They're definitions for anonymous objects which have a lifetime
>of the expression they're in.
No they aren't. To get that, you would need to write
int();
float();
B();
In fact even that wouldn't work, because there is an ambiguity between
declarations and expressions there which is resolved in favour of
declarations.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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
]
Author: Marcelo Cantos <marcelo@mds.rmit.edu.au>
Date: 1997/04/03 Raw View
mangino@saturn.planet.net (Reed Mangino) writes:
> I was surprised that this was valid so I did this:
>
> void main(void)
> {
> int;
> float;
> B;
> }
>
> The above compiles and runs fine.... These aren't definitions or
> declarations (are they?).
You'd better get another compiler. Neither g++ nor SunPro accept
this, and nor should they, AFAIK.
--
______________________________________________________________________
Marcelo Cantos, Research Assistant __/_ marcelo@mds.rmit.edu.au
Multimedia Database Systems Group, RMIT / _ Tel 61-3-9282-2497
723 Swanston St, Carlton VIC 3053 Aus/ralia ><_> Fax 61-3-9282-2490
Acknowledgements: errors - me; wisdom - God; funding - RMIT
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/04/04 Raw View
drew@qualcomm.com (Drew Eckhardt) writes:
|> In article <5hrcd0$584@jupiter.planet.net>,
|> Reed Mangino <mangino@saturn.planet.net> wrote:
|>
|> > int;
|> > float;
|> > B;
|>
|> >The above compiles and runs fine.... These aren't definitions or
|> >declarations (are they?).
|>
|> They're definitions for anonymous objects which have a lifetime
|> of the expression they're in.
Except that they are statements, and so cannot be in any expression. I
believe that the term used for them in C was "vacuous definitions", or
something like that; syntacticly, they are a definition, but they
neither define an object nor a new type.
|> Useful for doing things like
|>
|> needs_a_B (B(x,y,z));
|>
|> and smart pointers
|>
|> return (auto_ptr<B> (new B (x,y,z)));
Where do the above definitions come into play here?
--
James Kanze home: kanze@gabi-soft.fr +33 (0)1 39 55 85 62
office: kanze@vx.cit.alcatel.fr +33 (0)1 69 63 14 54
GABI Software, Sarl., 22 rue Jacques-Lemercier, F-78000 Versailles France
-- Conseils en informatique industrielle --
---
[ 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
]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1997/04/05 Raw View
James Kanze writes:
> drew@qualcomm.com (Drew Eckhardt) writes:
> |> In article <5hrcd0$584@jupiter.planet.net>,
> |> Reed Mangino <mangino@saturn.planet.net> wrote:
> |>
> |> > int;
> |> > float;
> |> > B;
> [...] I
> believe that the term used for them in C was "vacuous definitions", or
> something like that; syntacticly, they are a definition, but they
> neither define an object nor a new type.
So they are forbidden in C++ (see [dcl.dcl] paragraph 3 in CD2).
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
Universidade Estadual de Campinas, SP, Brasil
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Mario Contestabile" <contem00@cam.org>
Date: 1997/04/06 Raw View
Reed Mangino <mangino@saturn.planet.net> wrote in article
<5hs0dh$768@jupiter.planet.net>...
> Alexandre Oliva (oliva@dcc.unicamp.br) wrote:
> : Reed Mangino writes:
>
> : > void main(void)
> : > {
> : > int;
> : > float;
> : > B;
> : > }
>
>
> Just FYI: I have tried the above using MSVC++ 4.0 & 5.0 - no warnings
> whatsoever...
Actually, Compiling with a warning level of 2 or higher on MSVC 5.0 will
produce
Compiler Warning (level 2) C4091
'extended-attribute' : ignored on left of 'type' when no variable is
declared
but only for float; and/or double;
mcontest@universal.com
Mario Contestabile
---
[ 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
]
Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/04/08 Raw View
fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) writes:
|> No they aren't. To get that, you would need to write
|>
|> int();
|> float();
|> B();
|>
|> In fact even that wouldn't work, because there is an ambiguity between
|> declarations and expressions there which is resolved in favour of
|> declarations.
Really. I don't think that the above would be legal declarations. (I
don't think that a vacuous declaration is legal. Have I missed
something?)
The question is arduous, however, since they definitly do have the
syntax of a declaration, even if the declaration is not legal.
--
James Kanze home: kanze@gabi-soft.fr +33 (0)1 39 55 85 62
office: kanze@vx.cit.alcatel.fr +33 (0)1 69 63 14 54
GABI Software, Sarl., 22 rue Jacques-Lemercier, F-78000 Versailles France
-- Conseils en informatique industrielle --
---
[ 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
]
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1997/04/09 Raw View
Reed Mangino wrote:
>
> While programming last night I had a typo that surprised me.
> I declared a class B and meant to create an instance:
> B b(5);
> But, instead (the typo) I typed:
> B;
>
> I compiled and ran without issue (except for the fact that
> I had no b! :)
>
> I was surprised that this was valid so I did this:
>
> void main(void)
> {
> int;
> float;
> B;
> }
>
> The above compiles and runs fine.... These aren't definitions or
> declarations (are they?).
>
> Thanks for your time!
> Reed
I don't really know what your compiler does, but I can imagine
that it interprets it as definitions of int variables via the implicit
int rule, so it might be equivalent to
int main()
{
int int; // local int variable named "int" (hiding global int type)
::int float; // local int variable "float"
::int B; // local int variable "B"
return 0;
}
To test if this is what your compiler does you could add another line
to main, like this:
int main()
{
int;
float;
B;
return int*float+B; // works if the compiler did what I guessed
// gives compile time error otherwise
}
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]