Re: likely a supid problem
wij@seed.net.tw wrote:
On 10???2???, ??????2???57???, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
Rolf Magnus wrote:
w...@seed.net.tw wrote:
Hi:
I made a simple code(t.cpp) like below
#include <iostream>
int main()
{
std::cout << "helo! world.\n";
return(0);
};
$gcc t.cpp (causes the following dumps. What's the problem?)
You used gcc instead of g++.
... and put a semicolon after a global function...
... and misspelled 'hello'. :-)
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I used to put semicolons after an expression as possible. Because it
is easier to spot errors mechanically
for me and for compiler to report errors sooner. e.g.
struct A {
int f(int n) {
int i=0;
while(i<n) {
++i;
}; // this semicolon is often seen absent
That's fine. You have an empty statement after the body of the 'while'
statement.
do { --i;
if(i==1) {
} else {
}; // this semicolon is often seen absent
Again, you have an empty statement after the body of the 'else' part.
if(i==1) {
}; // this semicolon is often seen absent
Here too, you have an empty statement after the body of the 'if'.
} while(i>=0);
for(i=0; i<n; ++i) {
}; // this semicolon is often seen absent
Another empty statement.
for(i=0; i<n; ++i) try{
}
catch(...) {
return -1;
}; // this semicolon is often seen absent
And another one.
};
This is a superfluous, yet harmless, semicolon. It's *explicitly*
allowed in the body of a class (or a struct).
}; // end struct A
Is this a valid C++ program?
Yes, that's a valid C++ program.
> Even f() is global? Thanks first.
No, if 'f' is global, the semicolon following its body is a syntax
error. Empty statements are OK inside a function and inside a class
definition. Empty statements are *not* OK in the namespace scope.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask