Why doesn't nothrow work?

D

Dustan

This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.

I copied a program from http://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:

p= new (nothrow) int;

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out

It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.

I'm using Bloodshed Dev-C++ Version 4, on Microsoft Windows XP Version
5.1.2600. Any ideas as to what my problem might be?
 
V

Victor Bazarov

Dustan said:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not
C+ +.

I copied a program from
http://www.cplusplus.com/doc/tutorial/dynamic.html (if that's a bad
place to go for a tutorial, feel free to direct me elsewhere), and
the following line gets an error:

p= new (nothrow) int;


Have you tried

p = new (std::nothrow) int;

?
Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out

It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.

I'm using Bloodshed Dev-C++ Version 4, on Microsoft Windows XP Version
5.1.2600. Any ideas as to what my problem might be?

V
 
D

Dustan

Dustan said:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not
C+ +.
I copied a program from
http://www.cplusplus.com/doc/tutorial/dynamic.html(if that's a bad
place to go for a tutorial, feel free to direct me elsewhere), and
the following line gets an error:
p= new (nothrow) int;


Have you tried

p = new (std::nothrow) int;

?


Thanks for the response.

Yes I had tried that, and no, it didn't work. I didn't get the exact
same error messages, but it conveyed the same problem:
`::nothrow' undeclared (first use here)
confused by earlier errors, bailing out
 
R

red floyd

Dustan said:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.

I copied a program from http://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:

p= new (nothrow) int;

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out


Did you #include <new>?
 
Z

Zeppe

Dustan said:
This is the biggie that has been keeping me from even trying to use C+
+ for more than about 10 seconds: it doesn't work. I've been able to
get java and (of course) python programs to compile and run, but not C+
+.

C++ it's a little bit tricky but when you know how to use it it's very
powerful, more than python or java. It's worth the time ;)
I copied a program from http://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:

I don't know exactly, many tutorials in the net have got slight errors
or imperfections.
p= new (nothrow) int;

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out

It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.


Well, it's not. The brackets are just dummy, and then ignored, and the
token is interpreted as a function reference. But those are
technicalities for a learner, in my opinion. You will learn, with the
experience, to do this:

1) read the error: `nothrow' undeclared
2) why is undeclared? it's standard library! so, try std::nothrow
3) error: ‘nothrow’ is not a member of ‘std’... Damn!
4) why it is not? because everything in c++ has to be defined somewhere,
and all the things of the standard library are defined in a header file
5) pick a book, and check out std::nothrow
6) #include <memory>
7) it works!

;)

Regards,

Zeppe
 
D

Dustan

C++ it's a little bit tricky but when you know how to use it it's very
powerful, more than python or java. It's worth the time ;)

Yeah... they say that exact same thing over at c.l.python and
c.l.java. I get the feeling everyone's biased or something. ;)
I copied a program fromhttp://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:

I don't know exactly, many tutorials in the net have got slight errors
or imperfections.


p= new (nothrow) int;

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out
It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.

Well, it's not. The brackets are just dummy, and then ignored, and the
token is interpreted as a function reference. But those are
technicalities for a learner, in my opinion. You will learn, with the
experience, to do this:

1) read the error: `nothrow' undeclared
2) why is undeclared? it's standard library! so, try std::nothrow
3) error: 'nothrow' is not a member of 'std'... Damn!
4) why it is not? because everything in c++ has to be defined somewhere,
and all the things of the standard library are defined in a header file
5) pick a book, and check out std::nothrow
6) #include <memory>
7) it works!

;)

Regards,

Zeppe


Thanks to red floyd and Zeppe for their responses. Both <new> and
<memory> worked, which I must admit is only further confusing for me;
I guess I still have quite a ways to go.
 
R

red floyd

Dustan said:
C++ it's a little bit tricky but when you know how to use it it's very
powerful, more than python or java. It's worth the time ;)

Yeah... they say that exact same thing over at c.l.python and
c.l.java. I get the feeling everyone's biased or something. ;)
I copied a program fromhttp://www.cplusplus.com/doc/tutorial/dynamic.html
(if that's a bad place to go for a tutorial, feel free to direct me
elsewhere), and the following line gets an error:
I don't know exactly, many tutorials in the net have got slight errors
or imperfections.


p= new (nothrow) int;
Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function)
(Each undeclared identifier is reported only once
for each function it appears in.)
confused by earlier errors, bailing out
It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.

Well, it's not. The brackets are just dummy, and then ignored, and the
token is interpreted as a function reference. But those are
technicalities for a learner, in my opinion. You will learn, with the
experience, to do this:

1) read the error: `nothrow' undeclared
2) why is undeclared? it's standard library! so, try std::nothrow
3) error: 'nothrow' is not a member of 'std'... Damn!
4) why it is not? because everything in c++ has to be defined somewhere,
and all the things of the standard library are defined in a header file
5) pick a book, and check out std::nothrow
6) #include <memory>
7) it works!

;)

Regards,

Zeppe


Thanks to red floyd and Zeppe for their responses. Both <new> and
<memory> worked, which I must admit is only further confusing for me;
I guess I still have quite a ways to go.


#include <memory> working is mere coincidence. Your implementation's
version of <memory> references <new>. Per the Standard 20.4, <memory>
does not define nothrow. It's defined in <new> per 18.4/1.
 
V

Victor Bazarov

Dustan said:
[..]
Thanks to red floyd and Zeppe for their responses. Both <new> and
<memory> worked, which I must admit is only further confusing for me;

Why is it confusing you? 'nothrow' is a symbol. It needs to be
defined; and it is, in <new>. It is conceivable that <new> is
included into <memory> (although it doesn't have to be), so when
you include <memory>, you also implicitly include <new> (which is
what you actually need for 'nothrow').

It's similar to how 'NULL' is defined pretty much any time you pull
in *any* standard header (probably), while its actual residence is
in <cstddef>, <cstring>, <cstdio>, <ctime>, or <cwchar>. Don't
rely on NULL's definition to exist all the time, do include one of
the required headers for it.
I guess I still have quite a ways to go.

Most of us do, as well.

V
 
Z

Zeppe

red said:
Dustan wrote:

#include <memory> working is mere coincidence. Your implementation's
version of <memory> references <new>. Per the Standard 20.4, <memory>
does not define nothrow. It's defined in <new> per 18.4/1.



Citing the standard, I guess, is to simplify the things to the beginner,
isn't it? Anyway, you caught me, I didn't really checked up in the book ^^

Regards,

Zeppe
 
R

red floyd

Zeppe said:
Citing the standard, I guess, is to simplify the things to the beginner,
isn't it? Anyway, you caught me, I didn't really checked up in the book ^^

No, it's more to explain *why* #include <memory> is the wrong answer.
When in doubt, "because the Standard says so", is a good answer.
 
Z

Zeppe

red said:
No, it's more to explain *why* #include <memory> is the wrong answer.
When in doubt, "because the Standard says so", is a good answer.

I hope you will agree that it's unlikely that the OP will read the
standard... anyway, I didn't want to argue about that, sure citing the
standard is always the best way to solve a doubt (for me, it would have
been enough "nothrow is defined in new, not in memory", and I would have
checked it out), but sometimes, particularly when a beginner asks
something, it can sound a little bit harsh, you know, bumptious.

Just my personal impression, though..

Regards,

Zeppe
 
D

Dustan

I hope you will agree that it's unlikely that the OP will read the
standard...

Show me the standard and I'll look at it. It looks like it'll help me
break through some of the issues I'm experiencing.
 
Z

Zeppe

Dustan said:
Show me the standard and I'll look at it. It looks like it'll help me
break through some of the issues I'm experiencing.

The standard is not very easy to look at, much better a good book for
the beginners (like the stroustrup). It isn't even available for free.
The draft is available, and it's quite close to the actual standard:
ftp://ftp.research.att.com/dist/c++std/WP/CD2

Regards,

Zeppe
 
P

Pete Becker

Zeppe said:
The standard is not very easy to look at, much better a good book for
the beginners (like the stroustrup). It isn't even available for free.
The draft is available, and it's quite close to the actual standard:
ftp://ftp.research.att.com/dist/c++std/WP/CD2

It's close to the 1998 standard. It's a long ways from the 2003
standard. Why is it that so many "professional" programmers aren't
willing to pay $30 for current information?

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
D

Dustan

It's close to the 1998 standard. It's a long ways from the 2003
standard. Why is it that so many "professional" programmers aren't
willing to pay $30 for current information?

Because I'm not professional???
 
M

Markus Schoder

This is the biggie that has been keeping me from even trying to use C+ +
for more than about 10 seconds: it doesn't work. I've been able to get
java and (of course) python programs to compile and run, but not C+ +.

I copied a program from
http://www.cplusplus.com/doc/tutorial/dynamic.html (if that's a bad
place to go for a tutorial, feel free to direct me elsewhere), and the
following line gets an error:

p= new (nothrow) int;

Here are the errors I get (all on line 11, the one above):
`nothrow' undeclared (first use this function) (Each undeclared
identifier is reported only once for each function it appears in.)
confused by earlier errors, bailing out

It seems odd to me that it's calling 'nothrow' a function; is (XXX)
really valid functional notation in C++? I thought that syntax was
reserved for casts.


It is not calling `nothrow' a function. "first use this function" is
short for "the given position is the first use of this particular
undeclared identifier in this function". And the actual function name is
also part of the error message.
 
J

Jerry Coffin

Yeah... they say that exact same thing over at c.l.python and
c.l.java. I get the feeling everyone's biased or something. ;)

It's necessarily that anybody's biased -- it's just that "powerful"
doesn't really mean much about a programming language. C++ gives lots of
control at a finer level of detail than most other languages. In
exchange for that, it _requires_ you to control more of what's going on,
even in cases where most other languages provide a single option (or
perhaps a default option) that usually makes sense.

[ ... ]
Thanks to red floyd and Zeppe for their responses. Both <new> and
<memory> worked, which I must admit is only further confusing for me;
I guess I still have quite a ways to go.

<new> is where the standard says nothrow is defined. The C++ standard
allows inclusion of one standard header to also have the effect of
including any other standard headers the implementation chooses.

That's undoubtedly what's happening in the case of including <memory> --
on your implementation, it's including <new> indirectly; it's not
required to do so, however, so what you want to include is <new>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top