Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > behavior of new

Reply
Thread Tools

behavior of new

 
 
Tino
Guest
Posts: n/a
 
      08-01-2003
What is the standard behavior, if any, of the following.

int *p, n = 0;
p = new int[n];

Is p guaranteed not to be NULL, because it's not clear to me why it wouldn't be...

Regards,
Ryan
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      08-01-2003

"Tino" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> What is the standard behavior, if any, of the following.
>
> int *p, n = 0;
> p = new int[n];
>
> Is p guaranteed not to be NULL, because it's not clear to me why it

wouldn't be...
>
> Regards,
> Ryan


Its guaranteed not to be NULL, why should it be?

john



 
Reply With Quote
 
 
 
 
Reginald P. Smithford
Guest
Posts: n/a
 
      08-04-2003
Wouldn't p==NULL if there wasn't enough memory for new to succeed? I
haven't been paying much attention to the standard recently, but I
assume this is still true. But, other than this error condition, p is
guaranteed to be a valid address (which NULL is not), and different
from any other pointers allocated with new or malloc (not just
different from other ints allocated).

Reggy

"Victor Bazarov" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> "Tino" <(E-Mail Removed)> wrote...
> > What is the standard behavior, if any, of the following.
> >
> > int *p, n = 0;
> > p = new int[n];
> >
> > Is p guaranteed not to be NULL, because it's not clear to me why it

> wouldn't be...
>
> Yes, it is guaranteed not to be NULL, and it's guaranteed to be
> different from any other "int"'s address in the system.
>
> Victor

 
Reply With Quote
 
Jerry Coffin
Guest
Posts: n/a
 
      08-06-2003
In article <(E-Mail Removed)> , tino52
@yahoo.com says...
> What is the standard behavior, if any, of the following.
>
> int *p, n = 0;
> p = new int[n];
>
> Is p guaranteed not to be NULL, because it's not clear to me why
> it wouldn't be...


Assuming new didn't throw bad_alloc, p will be a unique, non-null
pointer, but dereferencing it will give undefined results.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript new-new-new-new-newbee weblinkunlimited@gmail.com Javascript 2 03-11-2008 01:15 AM
Strange linking behavior when overriding global new and malloc Ryan Mack C++ 0 05-24-2004 10:28 PM
New process started under ASP .NET - Different behavior in IIS 6 Sorin Dolha [MCSD .NET] ASP .Net 9 03-02-2004 02:22 PM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM
New NAV behavior? Rustiferion Computer Support 1 01-01-2004 01:47 AM



Advertisments