Accessing real and imaginary parts of a complex number
When debugging a program which uses (either C or C++), gdb
displays complex numbers as _M_value = xxx + yyy*I
(with a type of complex double
).
While debugging, I need to print that number multiplied by a factor.
The following does not work:
print a * 8.0
I get Argument to arithmetic operation not a number or boolean
.
Also, I cannot access the real and imaginary parts so that I can write a gdb macro to do the above. My current solution is to write a C function for manipulating complex values and arrays, and calling that function from gdb. Somehow, this just doesn't feel right.
If you use the standard C++ complex template then complex::real() and complex::imaj() should work.
my2c
Note : Was a comment ^^
您可以调用C库函数creal()
和cimag()
来分解数字。
上一篇: Visual Studio 2010 SP1 Beta慢速安装
下一篇: 访问复数的实部和虚部