Re: is it safe to access a complex<double> array as a double array of
twice the length?
On Jun 26, 7:05 am, Gianni Mariani <owebee...@gmail.com> wrote:
On Jun 26, 2:04 pm, huil...@gmail.com wrote:
Like in the following. Though it gives the expected result with
gcc4.0, is it really safe to do that?
No. Not safe.
Officially.
What if it's not double but some non-POD type?
double *is* a POD type. complex<T> is not a POD type.
I think he was asking about something like complex< BigNumber >.
Of course, "The effect of instantiating the template complex for
any type other than float, double, or long double is
unspecified" (=A726.3), so the question is moot.
It's not guaranteed to work. It may work on your particular
implementation.
There are in fact a number of very strong motiviations for an
implementation to make it work. It's guaranteed in Fortran, and
as an implementer, you want your complex to be compatible with
those of Fortran. In practice, I think you might actually be
able to risk it (but *only* for complex<float> and
complex<double>).
(I'm presuming that the reason the poster wants to do this is in
order to interface with some legacy code. Otherwise, I'd
consider it very bad practice, even if it were formally
guaranteed.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34