Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

New(nothrow) Problems

831 views
Skip to first unread message

Kris

unread,
Jun 18, 2004, 10:23:27 AM6/18/04
to
Hi All,

I've been experimenting with the use of (nothrow) with operator new but I
can't seem to get it to compile. I've done a bunch of reading and everything
I've read seems to indicate that I'm doing it properly but still no luck. If
anyone can shed some light on the problem, it would be greatly appreciated.
I am using VC++ .Net (7.1.3088) if it helps.


The Code
=======
#include <new>
using std::nothrow;
...
int* piMyInt = new(std::nothrow) int;


The Compile Error
=============
error C2061: syntax error : identifier 'nothrow'


@discussions.microsoft.com Ganesh

unread,
Jun 18, 2004, 11:34:01 AM6/18/04
to
I am able to compile the same code segment without any problems (I am using the same version as yours).

-Ganesh

"Kris" wrote:

> Hi All,
>
> I've been experimenting with the use of (nothrow) with operator new but I
> can't seem to get it to compile. I've done a bunch of reading and everything
> I've read seems to indicate that I'm doing it properly but still no luck. If
> anyone can shed some light on the problem, it would be greatly appreciated.
> I am using VC++ .Net (7.1.3088) if it helps.
>
>
> The Code
> =======
> #include <new>
> using std::nothrow;

> ....

tom_usenet

unread,
Jun 18, 2004, 12:56:46 PM6/18/04
to
On Fri, 18 Jun 2004 10:23:27 -0400, "Kris"
<kris_my...@hotmail.com> wrote:

>Hi All,
>
>I've been experimenting with the use of (nothrow) with operator new but I
>can't seem to get it to compile. I've done a bunch of reading and everything
>I've read seems to indicate that I'm doing it properly but still no luck. If
>anyone can shed some light on the problem, it would be greatly appreciated.
>I am using VC++ .Net (7.1.3088) if it helps.
>
>
>The Code
>=======
>#include <new>
>using std::nothrow;

Why have you got the using declaration?

>...
>int* piMyInt = new(std::nothrow) int;
>
>
>The Compile Error
>=============
>error C2061: syntax error : identifier 'nothrow'

Which line does the error point to?

This exact code:

#include <new>
using std::nothrow;

int* piMyInt = new(std::nothrow) int;

compiles without error for me. Have you got a '#define new' type
construct anywhere? MFC has that, as do some other libraries.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

Kris

unread,
Jun 18, 2004, 5:03:55 PM6/18/04
to
Thank-you for the response Tom. I tried a number of things based on the
comments that you made and discovered that the problem was related to a
#define statement. A number of the .cpp files in the project that I'm
working have the following code block in them.

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

After doing some more digging, I discovered that DEBUG_NEW is a MS macro
that allows VC++ to keep track of the filename and line number for each of
the items that it allocates. The following article on MSDN has further
details:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_debug_new.asp

My solution was to simply comment out that block of code in the file where I
was getting the compile error. Do you have any opinions on whether or not
this was the right approach to take? I would like the compiler to still be
able to keep track of the line number/file but not at the expense of being
able to specify nothrow.

"tom_usenet" <tom_u...@hotmail.com> wrote in message
news:bi76d0lloooho37qt...@4ax.com...

0 new messages