473,387 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

likely a supid problem

wij
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?)

/tmp/ccsRiwha.o(.text+0xd): In function `std::__verify_grouping(char
const*, unsigned int, std::basic_string<char, std::char_traits<char>,
std::allocator<char const&)':
: undefined reference to `std::basic_string<char,
std::char_traits<char>, std::allocator<char::size() const'
/tmp/ccsRiwha.o(.text+0x60): In function `std::__verify_grouping(char
const*, unsigned int, std::basic_string<char, std::char_traits<char>,
std::allocator<char const&)':
: undefined reference to `std::basic_string<char,
std::char_traits<char>, std::allocator<char::operator[](unsigned
int) const'
/tmp/ccsRiwha.o(.text+0x9d): In function `std::__verify_grouping(char
const*, unsigned int, std::basic_string<char, std::char_traits<char>,
std::allocator<char const&)':
: undefined reference to `std::basic_string<char,
std::char_traits<char>, std::allocator<char::operator[](unsigned
int) const'
"t" 30L, 2072C ¤w¼g¤J
Oct 1 '08 #1
6 1204
wi*@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++.

Oct 1 '08 #2
Rolf Magnus wrote:
wi*@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
Oct 1 '08 #3
wij
On 10$B7n(B2$BF|(B, $B>e8a(B2$B;~(B57$BJ,(B, Victor Bazarov <v.Abaza...@comAcast.netwrote:
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

do { --i;
if(i==1) {
} else {
}; // this semicolon is often seen absent

if(i==1) {
}; // this semicolon is often seen absent
} while(i>=0);

for(i=0; i<n; ++i) {
}; // this semicolon is often seen absent

for(i=0; i<n; ++i) try{
}
catch(...) {
return -1;
}; // this semicolon is often seen absent
};

}; // end struct A

Is this a valid C++ program? Even f() is global? Thanks first.

Oct 2 '08 #4
wi*@seed.net.tw wrote:
On 10月2æ—¥, 上åˆ2時57分, Victor Bazarov <v.Abaza...@comAcast.netwrote:
>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
Oct 2 '08 #5
On Oct 2, 10:05 pm, w...@seed.net.tw wrote:
On 10?2?, ??2?57?, Victor Bazarov <v.Abaza...@comAcast.netwrote:
Rolf Magnus wrote:
w...@seed.net.tw wrote:
>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'. :-)
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.
Putting a semicolon after an expression turns it into a
statement. If you want or need a statement, the semicolon is
required. If you don't want or need a statement, it's
forbidden. There's no case where you have a choice about a
semicolon after an expression.
struct A {
int f(int n) {
int i=0;
while(i<n) {
++i;
}; // this semicolon is often seen absent
Always absent, I would say. A while statement is terminated by
the statement it controls, and in practice, all statements are
terminated by either a closing brace or a semicolon. A
semicolon here only introduces an additional statement for
nothing, and can cause problems, e.g.:

if ( x )
while ( i < n ) {
++ i ;
}
else ...

Adding a semicolon after the while would cause an error.
do { --i;
if(i==1) {
} else {
}; // this semicolon is often seen absent
See above. Same problem. It's absent because it can cause
problems.
if(i==1) {
}; // this semicolon is often seen absent
} while(i>=0);
for(i=0; i<n; ++i) {
}; // this semicolon is often seen absent
for(i=0; i<n; ++i) try{
}
catch(...) {
return -1;
}; // this semicolon is often seen absent
};
The above is really the only context where a semicolon is really
optional, and doesn't do anything.
}; // end struct A
Is this a valid C++ program? Even f() is global?
All of these exact examples are legal, but you do have to be
careful. A semi-colon where one is not needed, EXCEPT after the
definition of a member function in the class, creates an
expression statement. That's an additional statement, which
isn't legal in all contexts, and can change the meaning in
sometimes unexpected ways in other contexts.

--
James Kanze (GABI Software) email:ja*********@gmail.com
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
Oct 3 '08 #6
On Oct 2, 10:16 pm, Victor Bazarov <v.Abaza...@comAcast.netwrote:
w...@seed.net.tw wrote:
On 10?2?, ??2?57?, Victor Bazarov <v.Abaza...@comAcast.netwrote:
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'. :-)
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.
Which is confusing to the reader, and could cause problems if an
if/else is later introduced around the while statement.

And just a nit: you know that it's an empty statement, and I
know it, but the C++ standard doesn't; there's no such thing as
an empty statement in C++. According to the standard, this is
an expression statement. Which has repercusions, because an
expression statement isn't legal except in a function.
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'.
An empty statement which isn't part of the if statement. Which
can lead to interesting consequences if you add an else.
Consider:

if ( a )
if ( b ) {
c ;
} ;
else { // This else associates with the first
// if, not the second.
}

} 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.
IMHO, it would be better if the standard did define empty
statements, and allowed them anywhere a declaration is allowed.
As it is, this is an expression statement, and of course,
expression statements are only allowed in a function. (Defining
empty statements this way would also eliminate the special case
for a semicolon after a function definition in a class.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
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
Oct 3 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Mason A. Clark | last post by:
If I use javascript on my page, how likely is it that the viewer will not have javascript? Anyone have data? Mason C
9
by: mkdunaway3 | last post by:
I'm just starting out here and I keep running into a basic problem. I build a set of tables: First Names, Last Names, Member Status. I bring these together in a table, Persons' Name & Status,...
4
by: Richard G. Riley | last post by:
Gnu C has a feature for optimised branching using likely() and unlikely() for branch conditions e.g if(likely(f)){ ... or
16
by: Jim Langston | last post by:
I know that functions starting with an underscore, or two underscores, are reserved by the compiler/c++ and should not be used by the user and may cause undefined behavior. My question is, how...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.