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

behavior of new

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
Jul 19 '05 #1
3 1417

"Tino" <ti****@yahoo.com> wrote in message
news:f9*************************@posting.google.co 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

Jul 19 '05 #2
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" <v.********@attAbi.com> wrote in message news:<vi************@corp.supernews.com>...
"Tino" <ti****@yahoo.com> 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

Jul 19 '05 #3
In article <f9*************************@posting.google.com> , 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.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Dave Rahardja | last post by:
Does the C++ standard specify the behavior of floating point numbers during "exceptional" (exceptional with respect to floating point numbers, not exceptions) conditions? For example: double...
19
by: E. Robert Tisdale | last post by:
In the context of the comp.lang.c newsgroup, the term "undefined behavior" actually refers to behavior not defined by the ANSI/ISO C 9 standard. Specifically, it is *not* true that "anything can...
23
by: Ken Turkowski | last post by:
The construct (void*)(((long)ptr + 3) & ~3) worked well until now to enforce alignment of the pointer to long boundaries. However, now VC++ warns about it, undoubtedly to help things work on 64...
38
by: Steven Bethard | last post by:
> >>> aList = > >>> it = iter(aList) > >>> zip(it, it) > > That behavior is currently an accident. >http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1121416
7
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We...
66
by: gyan | last post by:
Hi All, I am using sprintf and getting starnge output in following case char temp_rn; memset(temp_rn,'\0',12); sprintf(temp_rn,"0%s",temp_rn); the final value in temp_rn is 00 how it...
12
by: Rajesh S R | last post by:
Can anyone tell me what is the difference between undefined behavior and unspecified behavior? Though I've read what is given about them, in ISO standards, I'm still not able to get the...
28
by: v4vijayakumar | last post by:
#include <string> #include <iostream> using namespace std; int main() { string str; str.resize(5); str = 't';
35
by: bukzor | last post by:
I've found some bizzare behavior when using mutable values (lists, dicts, etc) as the default argument of a function. I want to get the community's feedback on this. It's easiest to explain with...
33
by: coolguyaroundyou | last post by:
Will the following statement invoke undefined behavior : a^=b,b^=a,a^=b ; given that a and b are of int-type ?? Be cautious, I have not written a^=b^=a^=b ; which, of course, is undefined....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.