2

A container class with the following interface:

template <typename T> class DynArray {
  /// Returns the number of elements in the array.
  inline size_t GetCount();
  /// Releases the internal memory from the \class DynArray
  /// and returns it. The memory must be deallocated manually.
  inline T* Release();
}

In a function call like

SomeFunction(arr.GetCount(), arr.Release())

I would have expected arr.GetCount() to be called before arr.Release(), but the reverse seems to actually happen causing the first parameter to be passed a value of 0 instead of the actual array size. I'm using Visual Studio 2012.

Does the C++ standard say anything specific about order of execution when evaluating function parameters?

Niklas R
  • 16,299
  • 28
  • 108
  • 203
  • The standard does not mandate the order of execution when passed as params, this is left to the implementor: http://stackoverflow.com/questions/2934904/order-of-evaluation-in-c-function-parameters – EdChum May 20 '15 at 10:59

1 Answers1

3

It says that the order is entirely unspecified.

The sequencing rules are far too complex to reproduce here, and it's hard to prove a negative, but a non-normative note conveniently summarises it for us:

[C++11: 5.2.2/4]: When a function is called, each parameter (8.3.5) shall be initialized (8.5, 12.8, 12.1) with its corresponding argument. [ Note: Such initializations are indeterminately sequenced with respect to each other (1.9) — end note ] [..]

(Identical text in C++14.)

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055