GNU C supports complex data types. You can declare both complex integer
types and complex floating types, using the keyword __complex__
.
For example, `__complex__ double x;' declares x
as a
variable whose real part and imaginary part are both of type
double
. `__complex__ short int y;' declares y
to
have real and imaginary parts of type short int
; this is not
likely to be useful, but it shows that the set of complex types is
complete.
To write a constant with a complex data type, use the suffix `i' or
`j' (either one; they are equivalent). For example, 2.5fi
has type __complex__ float
and 3i
has type
__complex__ int
. Such a constant always has a pure imaginary
value, but you can form any complex value you like by adding one to a
real constant.
To extract the real part of a complex-valued expression exp, write
__real__ exp
. Likewise, use __imag__
to
extract the imaginary part.
The operator `~' performs complex conjugation when used on a value with a complex type.
GNU CC can allocate complex automatic variables in a noncontiguous
fashion; it's even possible for the real part to be in a register while
the imaginary part is on the stack (or vice-versa). None of the
supported debugging info formats has a way to represent noncontiguous
allocation like this, so GNU CC describes a noncontiguous complex
variable as if it were two separate variables of noncomplex type.
If the variable's actual name is foo
, the two fictitious
variables are named foo$real
and foo$imag
. You can
examine and set these two fictitious variables with your debugger.
A future version of GDB will know how to recognize such pairs and treat them as a single variable with a complex type.