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:
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:
I can use the different formats to show the variables in a different format than hexadecimal:
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:
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:
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’:
I cast it to an integer pointer:
Now I can see the raw memory bytes with this trick:
If I don’t need that cast any more, I can restore the original type again:
Happy Floating 🙂
PS: Eclipse JDT (for Java) has cool Detail Formatter where I can write my own special formatter for varibles (http://www.robertwloch.net/2012/01/eclipse-tips-tricks-detail-formatter/). Unfortunately this still does not exist for Eclipse CDT 😦