C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

wrong or superfluous semicolon?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Ulrich Eckhardt
Guest





PostPosted: Wed Dec 08, 2004 10:56 pm    Post subject: wrong or superfluous semicolon? Reply with quote



// Typical example:
struct foo
{
foo(){};
};

Question is, whether the semicolon after the definition of foo's ctor is
only unnecessary or plain wrong?

thanks

Uli

--
FAQ: http://parashift.com/c++-faq-lite/
/* bittersweet C++ */
default: break;

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Woodstok
Guest





PostPosted: Thu Dec 09, 2004 9:19 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote



In other news:
Ulrich Eckhardt typed:
Quote:
// Typical example:
struct foo
{
foo(){};
};

Question is, whether the semicolon after the definition of foo's ctor
is only unnecessary or plain wrong?


Unnecessary but it won't cause any errors

Woodstok


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
loritsch@gmail.com
Guest





PostPosted: Thu Dec 09, 2004 9:21 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote




Ulrich Eckhardt wrote:
Quote:
foo(){};

It really depends on what you are trying to do...

While it is valid C++, the semicolon after foo(){} merely produces an
empty C++ statement after the function definition.

Since empty statements are allowed, there is nothing wrong with it.
Instead it is merely superfluous.

Regards,

Michael Loritsch


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
L.Suresh
Guest





PostPosted: Thu Dec 09, 2004 9:23 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote

The semicolon is unnecessary after the foo constructor.
But from compilers viewpoint, the definition of foo is complete after
the right brace.
Immediately after that it encounters another demarcator ";", but
without any intermediate tokens.
So the compiler proceeds after the semi colon.

IMHO, i think that its ony unnecessary, not wrong.

scattering unnecessary ";" may cause some surprise as in :
for (;Wink;
{
}

--lsu


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Sharad Kala
Guest





PostPosted: Thu Dec 09, 2004 9:23 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote


"Ulrich Eckhardt" <doomster (AT) knuut (DOT) de> wrote in message

Quote:
// Typical example:
struct foo
{
foo(){};
};

Question is, whether the semicolon after the definition of foo's ctor is
only unnecessary or plain wrong?

Unnecessary. Check the grammar in Annex A of the Standard.

Sharad



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Fri Dec 10, 2004 1:47 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote

[email]loritsch (AT) gmail (DOT) com[/email] wrote:
Quote:
Ulrich Eckhardt wrote:
foo(){};

It really depends on what you are trying to do...

While it is valid C++, the semicolon after foo(){} merely produces an
empty C++ statement after the function definition.

Since empty statements are allowed, there is nothing wrong with it.
Instead it is merely superfluous.

This is wrong on two counts.

First, the extra semicolon does not create an empty statement. The
grammar specifically includes an optional semicolon after an in class
member function definition.

Secondly, empty statments aren't allowed except in a function
definition. A second semicolon would create an empty statement, which
is illegal in this context. (I think that some compilers allow empty
statements anywhere, however, as an extension.)

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Seungbeom Kim
Guest





PostPosted: Fri Dec 10, 2004 1:48 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote

[email]loritsch (AT) gmail (DOT) com[/email] wrote:
Quote:
Ulrich Eckhardt wrote:
foo(){};

It really depends on what you are trying to do...

While it is valid C++, the semicolon after foo(){} merely produces an
empty C++ statement after the function definition.

Since empty statements are allowed, there is nothing wrong with it.
Instead it is merely superfluous.

It's not about empty statements here; the location of the semicolon is
outside a function body, where statements are not allowed.

But it should be about empty member declarations inside a class
definition. Just looking at the Annex A of the C++98 standard, an empty
member declaration seems possible because of the production

member-declaration:
decl-specifier-seq(opt) member-declarator-list(opt) ;

but Comeau C++ Online doesn't accept the following code:

struct foo
{
foo() { }
; // okay
; // error
; // error
};

where the first semicolon is okay but the rest are not.
I don't know what's happening here.


P.S. Does anyone know why all the hyphens are lost if I copy and paste
from the C++98 standard PDF file? If the error is in the file itself,
has it been corrected in the 2003 revision?

--
Seungbeom Kim

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Francis Glassborow
Guest





PostPosted: Fri Dec 10, 2004 1:55 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote

In article <31ogb6F3fa8cuU1 (AT) individual (DOT) net>, Ulrich Eckhardt
<doomster (AT) knuut (DOT) de> writes
Quote:
// Typical example:
struct foo
{
foo(){};
};

Question is, whether the semicolon after the definition of foo's ctor is
only unnecessary or plain wrong?

Read the grammar and you will find that a semicolon in that position is
optional (i.e. it isn't plain wrong, just superfluous)


--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
spuds
Guest





PostPosted: Fri Dec 10, 2004 2:06 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote



The semicolon is only required after the declaration
In your example you are making a definition. Actually it is a combined
declaration definition but the compiler views it as a definition.
Definitions of functions never require semicolons.

If you think about it, whenever you define the function out of line there
is never a requirement for a semi colon like this

struct foo
{
foo(); // a declaration
};

foo::foo()
{

// do something here to initialize foo

} /* end of definition of out of line function - no
semicolon required here because it is defined */








[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Andrey Tarasevich
Guest





PostPosted: Fri Dec 10, 2004 2:44 am    Post subject: Re: wrong or superfluous semicolon? Reply with quote

Ulrich Eckhardt wrote:
Quote:
// Typical example:
struct foo
{
foo(){};
};

Question is, whether the semicolon after the definition of foo's ctor is
only unnecessary or plain wrong?
...

It is unnecessary, but not wrong, as long as the function definition
resides inside the class definition. In the namespace scope a similar
semicolon (after function definition) would be an error.

--
Best regards,
Andrey Tarasevich

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Francis Glassborow
Guest





PostPosted: Fri Dec 10, 2004 12:30 pm    Post subject: Re: wrong or superfluous semicolon? Reply with quote

In article
<ac3724db53520b1a24492e787d8cf790 (AT) localhost (DOT) talkaboutprogramming.com>,
spuds <stevenhr (AT) kgh (DOT) kari.net> writes
Quote:
foo::foo()
{

// do something here to initialize foo

/* end of definition of out of line function - no
semicolon required here because it is defined */

Actually, it isn't just 'not required' but prohibited. The optional
semicolon for a member function definition is just for in-class
definitions.

Quote:


--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ben Hutchings
Guest





PostPosted: Thu Dec 16, 2004 6:20 pm    Post subject: Re: wrong or superfluous semicolon? Reply with quote

Seungbeom Kim wrote:
<snip>
Quote:
P.S. Does anyone know why all the hyphens are lost if I copy and paste
from the C++98 standard PDF file?

It is possible that the hyphens are wrongly being treated as "soft
hyphens", which mark potential line break points and should appear as
hyphens only if they are used as such.

Quote:
If the error is in the file itself, has it been corrected in the
2003 revision?

There is no such error in the 2003 changes prepared by Andrew Koenig,
and since the standard itself was prepared by a similar process, I
would guess it has been corrected.

--
Ben Hutchings
This sentence contradicts itself - no actually it doesn't.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.