[std-interval] default constructor

Ron Avitzur avitzur at PacificT.com
Fri Apr 7 15:56:20 PDT 2006


>a POD type has a copy constructor and a destructor for the sake of
>language uniformity, but a compiler should _never_ call them. As a
>matter of fact, it should not even generate them. And this is not a
>matter of optimizing or not: this is explicitly the point of a POD type.

I ran into a problem using CodeWarrior to compile for both PPC and x86 where

  Interval stack[kStackSize];

created a huge performance penalty due to the compiler generating an 
empty default constructor and passing a pointer to it to 
__construct_array which called it repeatedly, even at the highest 
optimization levels. (Interval is a POD-type in my implementation.) 
The run-time penalty this imposed did not show up on profiles, being 
absorbed by the function containing the local variable which I 
expected to be expensive, so it took a while to discover the problem.

While this case is just a compiler bug, it illustrates an issue for the API.

Having the interval default constructor initialize to some reasonable 
value can protect against one class of typical program error, but may 
introduce other problems. Programmers reasonably expect declaring a 
stack array of doubles to have no run-time cost. Any non-empty 
default initialization changes a declaration which may be expected to 
be free or constant-time as in the case of an array of doubles, into 
an operation which depends on the array size.

Ron Avitzur


More information about the Std-interval mailing list