Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a double variable with integer value using GDB?

Tags:

c

gdb

I have a variable with type double and I want to set it with a integer value.

For example:

double x;

In GDB, when I do :

set x = 14
p x
$1 = 14 //ok, looks right
x/xg &x
0x7fffffffec28: 0x402c000000000000 //oh no, this is a double representation and I want integer!

What I want is to x have an integer value x = 0xe instead of a double representation even if the variable is a double.

Thanks in advance!

like image 680
Pedro Caldeira Avatar asked Feb 15 '26 17:02

Pedro Caldeira


1 Answers

You can cast the type of the memory location:

p {int}&x=10
$4 = 10
x/xg &x
0x7f2c40 <x>:   0x000000000000000a
like image 187
stark Avatar answered Feb 18 '26 06:02

stark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!