Show Floating Point Variable Bytes in Eclipse CDT

My preferred variable format in Eclipse is hexadecimal (see “Debugging Variables in Hexadecimal with Eclipse“). However, this does not work well with floating point variables:

Floating Point Variables in Eclipse Variables View

Floating Point Variables in Eclipse Variables View

The above view shows all variables having the value 0x0 (zero), but that’s actually not really true.

💡 the Variable view is for local (stack) variables. For global (external) variables use the Expressions view (see “Variable Debugging with Eclipse“).

Eclipse has the ‘Variables detail pane’ which shows me that indeed the floating point value is 0.100000001 and not zero:

Variables Detail Pane

Variables Detail Pane

I can use the different formats to show the variables in a different format than hexadecimal:

Variables Number Format

Variables Number Format

Trying different format shows that ‘Details’ and ‘Default’ format shows the floating point value, while all the other formats (decimal, hexadecimal, binary and octal) cast the varible to an integral type and show the integral part of the variable only:

Different Variable Format

Different Variable Format

But what if I want to see the raw (byte) value of the floating point variable? Well, I could use the memory view (Memory view or Memory Browser view, see “Memory is everything“) for this at the address of that variable:

Floating Point Variable in Memory

Floating Point Variable in Memory

But because this might not be suitable to watch and monitor multiple floating point variables at the byte level, yet another way is to use the ‘type cast’:

Cast to Type

Cast to Type

I cast it to an integer pointer:

Cast to int pointer

Cast to int pointer

Now I can see the raw memory bytes with this trick:

float casted as int pointer

float casted as int pointer

If I don’t need that cast any more, I can restore the original type again:

Restore Original Type

Restore Original Type

Happy Floating 🙂

PS: Eclipse JDT (for Java) has cool Detail Formatter where I can write my own special formatter for varibles (www.robertwloch.net/2012/01/eclipse-tips-tricks-detail-formatter/). Unfortunately this still does not exist for Eclipse CDT 😦

1 thought on “Show Floating Point Variable Bytes in Eclipse CDT

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.