By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,381 Members | 1,561 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,381 IT Pros & Developers. It's quick & easy.

Is 'close' a reserved word in C++ ?

P: n/a
The following code does not compile:

#include <iostream>

class close {
public:
void message();
};

inline void close::message()
{
std::cout << "Close class\n";
}

int main()
{
close c;

c.message();
}

The message given by g++ is:

other.cc: In function `int main()':
other.cc:15: error: `close' undeclared (first use this function)
other.cc:15: error: (Each undeclared identifier is reported only once for each
function it appears in.)
other.cc:15: error: syntax error before `;' token
other.cc:17: error: `c' undeclared (first use this function)

I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.

--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
Dec 29 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a

Roman Werpachowski wrote:
The following code does not compile:

#include <iostream>

class close {
public:
void message();
};

inline void close::message()
{
std::cout << "Close class\n";
}

int main()
{
close c;

c.message();
}

The message given by g++ is:

other.cc: In function `int main()':
other.cc:15: error: `close' undeclared (first use this function)
other.cc:15: error: (Each undeclared identifier is reported only once for each
function it appears in.)
other.cc:15: error: syntax error before `;' token
other.cc:17: error: `c' undeclared (first use this function)

I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.


close is not a reserved word in C++. Comeau compiles your program
fine. What version of gcc are you using?

Best regards,

Tom

Dec 29 '05 #2

P: n/a
On the 28 Dec 2005 17:04:18 -0800, Thomas Tutone wrote:
I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.


close is not a reserved word in C++. Comeau compiles your program
fine. What version of gcc are you using?


3.3.6 compiled for x86_64
--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
Dec 29 '05 #3

P: n/a
On the Thu, 29 Dec 2005 01:08:16 +0000 (UTC), Roman Werpachowski wrote:
On the 28 Dec 2005 17:04:18 -0800, Thomas Tutone wrote:
I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.


close is not a reserved word in C++. Comeau compiles your program
fine. What version of gcc are you using?


3.3.6 compiled for x86_64


The darn thing compiles when I remove

#include <iostream>

line.

--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
Dec 29 '05 #4

P: n/a
On the Thu, 29 Dec 2005 01:11:17 +0000 (UTC), Roman Werpachowski wrote:
On the Thu, 29 Dec 2005 01:08:16 +0000 (UTC), Roman Werpachowski wrote:
On the 28 Dec 2005 17:04:18 -0800, Thomas Tutone wrote:
I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.

close is not a reserved word in C++. Comeau compiles your program
fine. What version of gcc are you using?


3.3.6 compiled for x86_64


The darn thing compiles when I remove

#include <iostream>

line.


It seems there are close() methods defined in std:: namespace. But I did
*not* write:

using namespace std;

in the original source!
--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
Dec 29 '05 #5

P: n/a
It seems there are close() methods defined in std:: namespace. But I did
*not* write:

using namespace std;


it doesn't make sense. There is a different reason -- likely a COMPILE
RELATED.

anyone knows the exact rules for look up?

Dec 29 '05 #6

P: n/a
Roman Werpachowski wrote:
I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.


The problem is almost certainly the declaration of POSIX' 'close()'
function. This is declared via implicit inclusion of <unistd.h> from
<iostream>. Although I would guess that most if not all implementations
on POSIX systems include this header, I would consider it to be a bug
in the implementation. However, conflicting with names of system
functions in global scope is probably best avoided.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Dec 29 '05 #7

P: n/a
Roman Werpachowski wrote:
The following code does not compile:

#include <iostream>

class close {
public:
void message();
};

inline void close::message()
{
std::cout << "Close class\n";
}

int main()
{
close c;

c.message();
}

The message given by g++ is:

other.cc: In function `int main()':
other.cc:15: error: `close' undeclared (first use this function)
other.cc:15: error: (Each undeclared identifier is reported only once for each
function it appears in.)
other.cc:15: error: syntax error before `;' token
other.cc:17: error: `c' undeclared (first use this function)

I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.


You mean if you actually copy/paste what's written in your message you
get these errors? This seems highly unlikely to me.
Jonathan

Dec 29 '05 #8

P: n/a
On the 28 Dec 2005 18:12:30 -0800, Jonathan Mcdougall wrote:
You mean if you actually copy/paste what's written in your message you
get these errors?
Yup.
This seems highly unlikely to me.


So now there is two of us.
--
Roman Werpachowski
/--------==============--------\
| http://www.cft.edu.pl/~roman |
\--------==============--------/
Dec 29 '05 #9

P: n/a
Roman Werpachowski wrote:
I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.


I think you might be a bit unwise to choose a word that is not
reservered, but one might reasonably think might be in a later revision
of the dynamic C++ language. close_file is not descriptive, but less
likely to become a reservered word in the future.
--
Dave K

http://www.southminster-branch-line.org.uk/

Please note my email address changes periodically to avoid spam.
It is always of the form: month-year@domain. Hitting reply will work
for a couple of months only. Later set it manually. The month is
always written in 3 letters (e.g. Jan, not January etc)
Dec 29 '05 #10

P: n/a
Dave wrote:
Roman Werpachowski wrote:
I don't understand it. I've looked for a list of reserved words in C++
and
'close' is not there.


I think you might be a bit unwise to choose a word that is not
reservered, but one might reasonably think might be in a later revision
of the dynamic C++ language. close_file is not descriptive,


Sorry, that was supposed to be "close file is not only more descriptive ..."
--
Dave K

http://www.southminster-branch-line.org.uk/

Please note my email address changes periodically to avoid spam.
It is always of the form: month-year@domain. Hitting reply will work
for a couple of months only. Later set it manually. The month is
always written in 3 letters (e.g. Jan, not January etc)
Dec 29 '05 #11

P: n/a
"Jonathan Mcdougall" <jo***************@gmail.com> writes:
Roman Werpachowski wrote:
The following code does not compile:

#include <iostream>

class close {
public:
void message();
};

inline void close::message()
{
std::cout << "Close class\n";
}

int main()
{
close c;

c.message();
}

The message given by g++ is:

other.cc: In function `int main()':
other.cc:15: error: `close' undeclared (first use this function)
other.cc:15: error: (Each undeclared identifier is reported only once for each
function it appears in.)
other.cc:15: error: syntax error before `;' token
other.cc:17: error: `c' undeclared (first use this function)

I don't understand it. I've looked for a list of reserved words in C++ and
'close' is not there.


You mean if you actually copy/paste what's written in your message you
get these errors? This seems highly unlikely to me.


I copied / pasted the exact code written in the message and compiled it
with gcc 3.4.1 and gcc 4.1.0 on FreeBSD, and I got similar but not
identical error messages, so what seems highly unlikely to you seems
highly likely to me.

The reason is a bug in gcc's <iostream>, which includes a header, which
includes a header, which includes a header ..., which includes <unistd.h>,
which declares the function close() in the global namespace.

<OT>
Invokation of gcc with -E switch, and then grep are handy tools when
dealing with such errors.
</OT>

/Niklas Norrthon
Dec 29 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.