Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

Why doesn't nothrow work?


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[i];

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?

Dustan wrote:
> 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[i];

Have you tried

    p = new (std::nothrow) int[i];

?

> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On May 29, 12:02 pm, "Victor Bazarov" <v.Abaza@comAcast.net> wrote:

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

Did you #include <new>?

Dustan wrote:
> 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[i];

> 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

On May 29, 12:46 pm, Zeppe

<zep_p@.remove.all.this.long.comment.yahoo.it> wrote:
> Dustan wrote:
> > 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 ;)

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. ;)

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.

Dustan wrote:
> [..]
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

#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.

red floyd wrote:
> Dustan wrote:
>> 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.

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

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.

red floyd wrote:
> Zeppe wrote:
>> 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.

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

On May 30, 3:54 am, Zeppe

<zep_p@.remove.all.this.long.comment.yahoo.it> wrote:
> red floyd wrote:
> > Zeppe wrote:
> >> 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.

> 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.

Dustan wrote:
> On May 30, 3:54 am, Zeppe
> <zep_p@.remove.all.this.long.comment.yahoo.it> wrote:
>> red floyd wrote:
>>> Zeppe wrote:
>>>> 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.
>> 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.

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

Zeppe wrote:

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

On May 30, 10:57 am, Pete Becker <p@versatilecoding.com> wrote:

> Zeppe wrote:

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

Because I'm not professional???

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.

--
Markus Schoder

In article <1180461348.513674.41@k79g2000hse.googlegroups.com>,
DustanGro@gmail.com says...

> On May 29, 12:46 pm, Zeppe
> <zep_p@.remove.all.this.long.comment.yahoo.it> wrote:
> > Dustan wrote:
> > > 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 ;)

> 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>.

--
    Later,
    Jerry.

The universe is a figment of its own imagination.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc