|
-
March 2nd, 2004, 06:39 PM
#1
another childish 'exception' question
if...
int main(void) {
int * p(some_value);
p = new int;
...
return 0;
}
Assume that the 'new' invocation fails generating a 'bad_alloc' exception... is the value of p modified? if so, is the value undefined? My gut feel would be that p is not modified and (p == some_value) still holds true but I'd like some confirmation on this.
The views expressed are those of the author and do not reflect any position taken by the Goverment of the United States of America, National Aeronautics and Space Administration (NASA), Jet Propulsion Laboratory (JPL), or California Institute of Technology (CalTech)
-
March 2nd, 2004, 08:13 PM
#2
I believe that the exception should be thrown from within the new operator or any underlying function. Thus it shoudn't be affecting the pointer, p.
-
March 3rd, 2004, 04:54 AM
#3
Remember that you have two operators in that expression: the new operator and the assignment operator. Assignment operators for fundamental types do not throw exceptions, so only the new operator could throw, which will happen before the assignment operator is invoked.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|