This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Is avoding calling default constructor possible?
- From: Åukasz Lew <lukasz dot lew at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 2 Nov 2009 04:13:19 +0100
- Subject: Is avoding calling default constructor possible?
Hi,
Is it possible to create array of objects T without calling the
default constructors T::T() ?
Calling other constructor instead would be great.
Leaving the memory uninitalize is ok as well, as I can do placement new later.
I want to avoid char* casting to T* because it breaks strict aliasing rules
(stopping optimizations from happening and slowing my program by 25%.)
Answer to this question would provide walkaround to the aliasing
problem I described few days ago.
Thanks in advance for any ideas
Lukasz Lew
PS
Manual says that uinon is the way to go with strict-aliasing, but unfortunately:
union {
char tab [N * sizeof(Elt)];
Elt tab2 [N];
};
Doesn't compile because Elt *has* default constructor.