473,395 Members | 1,629 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,395 software developers and data experts.

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

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
11 2743

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
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
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
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
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
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
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matthew Cascio | last post by:
My understanding is that using reserved words as column names is allowable as long as they are quoted. I am trying to create a table dynamically with columns defined by the first row of a text...
2
by: Jessard | last post by:
Hi All, I am writing a .NET app that accesses an access View. The view has a table column called 'Position'. When i try and right an UpdateCommand string for this using this column I am...
1
by: James Boulter | last post by:
Dear all, I have a database in which one column is titled 'force'. Now that this has become a reserved word, virtually no commands will execute, including of course a query to change the column...
4
by: Lerp | last post by:
Hi, I have this sub in which I am trying to get a client name from a second table based on a clientid value in my datalist. I am having problems grabbing the clientid value out of my datalist...
17
by: Benoit Martin | last post by:
I'm working on a project in VB.net connecting to a SQL Server 2000 database that I can't modify I created a dataset with a schema identical to the DB. When trying to update the DB from the dataset...
3
by: VK | last post by:
Just to realease my frustration: innocent "enum" is a reserved word in JScript! !@#$%^&* I occasionally discovered it just before I got ready to smash my computer over my head (some people...
31
by: metaperl | last post by:
-- python -i File "<stdin>", line 1 class = "algebra" ^ SyntaxError: invalid syntax Why isn' t the parser smart enough to see that class followed by an identifier is used for class...
3
by: Robert | last post by:
I ask because, in Access help, it does not list is as such, however, I had a table with a field named 'Name'. If I put a control on a form and used this as the control source no problems, but if I...
10
by: Heinrich Wolf | last post by:
Hi all, Please direct me to a current treatise of window.close(). My info is that a window can be closed provided it has been opened by the same script or functions within the same document....
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.