This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Can I use -data-evaluate-expression to evaluate sin(4.1)?


Nick Roberts wrote:
> -data-evaluate-expression sin(5.1)
> ^done,value="3"
> (gdb)
> > > Can I use "-data-evaluate-expression" to evaluate
> sin(x) function? If yes, why it returns a wrong
> "int" value?


By default (without debuginfo as Frederic says) it assumes sin takes an
integer argument and returns an value (I think).

You need to cast sin explicitly:

 (gdb)
-data-evaluate-expression "((double ((*) (double))) sin) (5.1)"
^done,value="-0.92581468232773245"
(gdb)
-data-evaluate-expression "((double ((*) (double))) sin) (4.1)"
^done,value="-0.81827711106441026"


Thank you very much for the explanation!
I verified that "ptype sin" gets wrong type ("int"):
ptype sin
&"ptype sin\n"
~"type = \n"
~"    int (void)\n"
^done

And thank you for the workaround, probably we can use it for
known functions (sin, cos, ...).




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]