# typedef double complex[2]

Discussion in 'C Programming' started by seia0106, May 11, 2004.

1. ### seia0106Guest

Hello,
I have an array
X=[0,0,1,0,0,0,-1,0,0,0,1,0,0,0,-1,0], whose even and odd indices
should represent
real and imaginary parts of complex numbers.
This I want to use in a routine that uses the
typedef double Cx[2]; for storing complex numbers.

I want to declare an array of complex numbers(with 8 elements) of this
type(Cx), such that even and odd indices of array X are loaded as real
and imaginary parts of complex numbers of this array. Would someone
please tell me how this can be done?

Thanks.

seia0106, May 11, 2004

2. ### Kevin BraceyGuest

In message <>
(seia0106) wrote:

> Hello,
> I have an array
> X=[0,0,1,0,0,0,-1,0,0,0,1,0,0,0,-1,0], whose even and odd indices
> should represent
> real and imaginary parts of complex numbers.
> This I want to use in a routine that uses the
> typedef double Cx[2]; for storing complex numbers.
>
> I want to declare an array of complex numbers(with 8 elements) of this
> type(Cx), such that even and odd indices of array X are loaded as real
> and imaginary parts of complex numbers of this array. Would someone
> please tell me how this can be done?

Given the typedef, an array of complex numbers can be defined and initialised
as:

Cx myarray[8] = { {0,0}, {1,0}, {0,0}, {-1,0},
{0,0}, {1,0}, {0,0}, {-1,0} };

The inner braces can be optionally omitted, but it's probably best to
keep them for clarity.