Item 20. An Unmanaged Pointer Problem, Part 1: Parameter Evaluation

I l @ ve RuBoard

Difficulty: 6

Readers of Exceptional C++ and this book know that exception safety is anything but trivial. This Item points out an exception safety problem that was discovered fairly recently, and shows how best to avoid it in your own code.

  1. In each of the following statements, what can you say about the order of evaluation of the functions f , g , and h and the expressions expr1 and expr2 ? Assume that expr1 and expr2 do not contain more function calls.

     // Example 20-1(a) // f( expr1, expr2 ); // Example 20-1(b) // f( g( expr1 ), h( expr2 ) ); 
  2. In your travels through the dusty corners of your company's code archives, you find the following code fragment:

     // Example 20-2 // // In some header file: void f( T1*, T2* ); // In some implementation file: f( new T1, new T2 ); 

    Does this code have any potential exception safety problems? Explain.

I l @ ve RuBoard


More Exceptional C++
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions
ISBN: 020170434X
EAN: 2147483647
Year: 2001
Pages: 118
Authors: Herb Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net